<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>linked list | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/linked-list/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Sat, 09 Jun 2012 11:15:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>C program to implement linked list</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-to-implement-linked-list/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-to-implement-linked-list/#comments</comments>
		
		<dc:creator><![CDATA[Drithi]]></dc:creator>
		<pubDate>Thu, 07 Jun 2012 09:09:38 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[data strucure]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=3147</guid>

					<description><![CDATA[<p>Below given C program implements linked list #include #include #include struct list { int data; struct list *next,*prev; }*head=NULL; void main() { void insert(); void del(); int c; clrscr(); /****************************************************************/ printf("\n\tOUTPUT::\n"); printf("\n\t1:insert \t\t2:delete\n\t3:exit"); while(1) { printf("\n\tENTER CHOICE: "); scanf("%d",&#038;c); switch(c) { case 1: insert(); break; case 2: del(); break; case 3: exit(1); } } }</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-to-implement-linked-list/">C program to implement linked list</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Below given C program implements linked list</p>
<pre lang="c" line="1">
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct list
{
    int data;
    struct list *next,*prev;
}*head=NULL;
void main()
{
    void insert();
    void del();
    int c;
    clrscr();

    /****************************************************************/

    printf("\n\tOUTPUT::\n");
    printf("\n\t1:insert \t\t2:delete\n\t3:exit");
    while(1)
    {
        printf("\n\tENTER CHOICE: ");
        scanf("%d",&c);
        switch(c)
        {
        case 1: insert();  break;
        case 2: del();  break;
        case 3: exit(1);
        }
    }
}
/*************************************************************/
void insert()
{
    struct list *temp,*new1,*pr;
    int pos,i=1;
    char ch;
    temp=head;
    printf("\tENTER POSITION TO BE INSERTED: ");
    scanf("%d",&pos);
    new1=(struct list*)malloc(sizeof(struct list));
    printf("\tENTER DATA: ");
    scanf("%d",&new1->data);
    if(pos==1)
    {
        new1->next=temp;
        head=new1;
    }
    else
    {
        while(i
            <pos)
        {
            pr=temp;
            temp=temp->next;
            i++;
        }
        temp->prev=new1;
        new1->next=temp;
        new1->prev=pr;
        pr->next=new1;
    }
}
/****************************************************************/
void del()
{
    struct list *temp,*pr,*t;
    int pos,i=1;
    temp=pr=head;
    printf("\tENTER POSITION TO BE DELETED: ");
    scanf("%d",&pos);
    temp=head;
    while(i
        <pos)
    {
        pr=temp;
        temp=temp->next;
        i++;
    }
    t=temp;
    temp=temp->next;
    pr->next=temp;
    temp->prev=pr;
    free(t);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-to-implement-linked-list/">C program to implement linked list</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-to-implement-linked-list/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to implement B-Trees</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-b-trees/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-b-trees/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Wed, 02 Feb 2011 12:27:29 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[B trees]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1277</guid>

					<description><![CDATA[<p>#include #include #include const int MAX = 4 ; const int MIN = 2 ; struct btnode { int count ; int value[MAX + 1] ; btnode *child[MAX + 1] ; } ; class btree { private : btnode *root ; public : btree( ) ; void insert ( int val ) ; int setval</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-b-trees/">C++ program to implement B-Trees</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
#include <stdlib.h>
#include <alloc.h>
const int MAX = 4 ;
const int MIN = 2 ;
struct btnode
{
	int count ;
	int value[MAX + 1] ;
	btnode *child[MAX + 1] ;
} ;
class btree
{
	private :
		btnode *root ;
	public :
		btree( ) ;
		void insert ( int val ) ;
		int setval ( int val, btnode *n, int *p, btnode **c ) ;
		static btnode * search ( int val, btnode *root, int *pos ) ;
		static int searchnode ( int val, btnode *n, int *pos ) ;
		void fillnode ( int val, btnode *c, btnode *n, int k ) ;
		void split ( int val, btnode *c, btnode *n,
				int k, int *y, btnode **newnode ) ;
		void del ( int val ) ;
		int delhelp ( int val, btnode *root ) ;
		void clear ( btnode *root, int k ) ;
		void copysucc ( btnode *root, int i ) ;
		void restore ( btnode *root, int i ) ;
		void rightshift ( int k ) ;
		void leftshift ( int k ) ;
		void merge ( int k ) ;
		void show( ) ;
		static void display ( btnode *root ) ;
		static void deltree ( btnode *root ) ;
		~btree( ) ;
} ;

btree :: btree( )
{
	root = NULL ;
}
void btree :: insert ( int val )
{
	int i ;
	btnode *c, *n ;
	int flag ;
	flag = setval ( val, root, &i, &c ) ;
	if ( flag )
	{
		n = new btnode ;
		n -> count = 1 ;
		n -> value[1] = i ;
		n -> child[0] = root ;
		n -> child[1] = c ;
		root = n ;
	}
}
int btree :: setval ( int val, btnode *n, int *p, btnode **c )
{
	int k ;
	if ( n == NULL )
	{
		*p = val ;
		*c = NULL ;
		return 1 ;
	}
	else
	{
		if ( searchnode ( val, n, &k ) )
			cout << endl << "Key value already exists." << endl ;
		if ( setval ( val, n -> child[k], p, c ) )
		{
			if ( n -> count < MAX )
			{
				fillnode ( *p, *c, n, k ) ;
				return 0 ;
			}
			else
			{
				split ( *p, *c, n, k, p, c ) ;
				return 1 ;
			}
		}
		return 0 ;
	}
}
btnode * btree :: search ( int val, btnode *root, int *pos )
{
	if ( root == NULL )
		return NULL ;
	else
	{
		if ( searchnode ( val, root, pos ) )
			return root ;
		else
			return search ( val, root -> child[*pos], pos ) ;
	}
}
int btree :: searchnode ( int val, btnode *n, int *pos )
{
	if ( val < n -> value[1] )
	{
		*pos = 0 ;
		return 0 ;
	}
	else
	{
		*pos = n -> count ;
		while ( ( val < n -> value[*pos] ) && *pos > 1 )
			( *pos )-- ;
		if ( val == n -> value[*pos] )
			return 1 ;
		else
			return 0 ;
	}
}
void btree :: fillnode ( int val, btnode *c, btnode *n, int k )
{
	int i ;
	for ( i = n -> count ; i > k ; i-- )
	{
		n -> value[i + 1] = n -> value[i] ;
		n -> child[i + 1] = n -> child[i] ;
	}
	n -> value[k + 1] = val ;
	n -> child[k + 1] = c ;
	n -> count++ ;
}
void btree :: split ( int val, btnode *c, btnode *n,
		int k, int *y, btnode **newnode )
{
	int i, mid ;

	if ( k <= MIN )
		mid = MIN ;
	else
		mid = MIN + 1 ;

	*newnode = new btnode ;

	for ( i = mid + 1 ; i <= MAX ; i++ )
	{
		( *newnode ) -> value[i - mid] = n -> value[i] ;
		( *newnode ) -> child[i - mid] = n -> child[i] ;
	}

	( *newnode ) -> count = MAX - mid ;
	n -> count = mid ;

	if ( k <= MIN )
		fillnode ( val, c, n, k ) ;
	else
		fillnode ( val, c, *newnode, k - mid ) ;

	*y = n -> value[n -> count] ;
	( *newnode ) -> child[0] = n -> child[n -> count] ;
	n -> count-- ;
}
void btree :: del ( int val )
{
	btnode * temp ;

	if ( ! delhelp ( val, root ) )
		cout << endl << "Value " << val << " not found." ;
	else
	{
		if ( root -> count == 0 )
		{
			temp = root ;
			root = root -> child[0] ;
			delete temp ;
		}
	}
}
int btree :: delhelp ( int val, btnode *root )
{
	int i ;
	int flag ;

	if ( root == NULL )
		return 0 ;
	else
	{
		flag = searchnode ( val, root, &i ) ;
		if ( flag )
		{
			if ( root -> child[i - 1] )
			{
				copysucc ( root, i ) ;
				flag = delhelp ( root -> value[i], root -> child[i] ) ;
				if ( !flag )
					cout << endl << "Value " << val << " not found." ;
			}
			else
				clear ( root, i ) ;
		}
		else
			flag = delhelp ( val, root -> child[i] ) ;
		if ( root -> child[i] != NULL )
		{
			if ( root -> child[i] -> count < MIN )
				restore ( root, i ) ;
		}
		return flag ;
	}
}
void btree :: clear ( btnode *root, int k )
{
	int i ;
	for ( i = k + 1 ; i <= root -> count ; i++ )
	{
		root -> value[i - 1] = root -> value[i] ;
		root -> child[i - 1] = root -> child[i] ;
	}
	root -> count-- ;
}
void btree :: copysucc ( btnode *root, int i )
{
	btnode *temp = root -> child[i] ;

	while ( temp -> child[0] )
		temp = temp -> child[0] ;

	root -> value[i] = temp -> value[1] ;
}
void btree :: restore ( btnode *root, int i )
{
	if ( i == 0 )
	{
		if ( root -> child [1] -> count > MIN )
			leftshift ( 1 ) ;
		else
			merge ( 1 ) ;
	}
	else
	{
		if ( i == root -> count )
		{
			if ( root -> child[i - 1] -> count > MIN )
				rightshift ( i ) ;
			else
				merge ( i ) ;
		}
		else
		{
			if ( root -> child[i - 1] -> count > MIN )
				rightshift ( i ) ;
			else
			{
				if ( root -> child[i + 1] -> count > MIN )
					leftshift ( i + 1 ) ;
				else
					merge ( i ) ;
			}
		}
	}
}
void btree :: rightshift ( int k )
{
	int i ;
	btnode *temp ;

	temp = root -> child[k] ;

	for ( i = temp -> count ; i > 0 ; i-- )
	{
		temp -> value[i + 1] = temp -> value[i] ;
		temp -> child[i + 1] = temp -> child[i] ;
	}

	temp -> child[1] = temp -> child[0] ;
	temp -> count++ ;
	temp -> value[1] = root -> value[k] ;
	temp = root -> child[k - 1] ;
	root -> value[k] = temp -> value[temp -> count] ;
	root -> child[k] -> child [0] = temp -> child[temp -> count] ;
	temp -> count-- ;
}
void btree :: leftshift ( int k )
{
	btnode *temp ;

	temp = root -> child[k - 1] ;
	temp -> count++ ;
	temp -> value[temp -> count] = root -> value[k] ;
	temp -> child[temp -> count] = root -> child[k] -> child[0] ;
	temp = root -> child[k] ;
	root -> value[k] = temp -> value[1] ;
	temp -> child[0] = temp -> child[1] ;
	temp -> count-- ;
	for ( int i = 1 ; i <= temp -> count ; i++ )
	{
		temp -> value[i] = temp -> value[i + 1] ;
		temp -> child[i] = temp -> child[i + 1] ;
	}
}
void btree :: merge ( int k )
{
	btnode *temp1, *temp2 ;
	temp1 = root -> child[k] ;
	temp2 = root -> child[k - 1] ;
	temp2 -> count++ ;
	temp2 -> value[temp2 -> count] = root -> value[k] ;
	temp2 -> child[temp2 -> count] = root -> child[0] ;
	for ( int i = 1 ; i <= temp1 -> count ; i++ )
	{
		temp2 -> count++ ;
		temp2 -> value[temp2 -> count] = temp1 -> value[i] ;
		temp2 -> child[temp2 -> count] = temp1 -> child[i] ;
	}
	for ( i = k ; i < root -> count ; i++ )
	{
		root -> value[i] = root -> value[i + 1] ;
		root -> child[i] = root -> child[i + 1] ;
	}
	root -> count-- ;
	delete temp1 ;
}
void btree :: show( )
{
	display ( root ) ;
}
void btree :: display ( btnode *root )
{
	if ( root != NULL )
	{
		for ( int i = 0 ; i < root -> count ; i++ )
		{
			display ( root -> child[i] ) ;
			cout << root -> value[i + 1] << "\t" ;
		}
		display ( root -> child[i] ) ;
	}
}
void btree :: deltree ( btnode *root )
{
	if ( root != NULL )
	{
		for ( int i = 0 ; i < root -> count ; i++ )
		{
			deltree ( root -> child[i] ) ;
			delete ( root -> child[i] ) ;
		}
		deltree ( root -> child[i] ) ;
		delete ( root -> child[i] ) ;
	}
}

btree :: ~btree( )
{
	deltree ( root ) ;
}

void main( )
{
	btree b ;
	int arr[ ] = { 27, 42, 22, 47, 32, 2, 51, 40, 13 } ;
	int sz = sizeof ( arr ) / sizeof ( int ) ;
	for ( int i = 0 ; i < sz ; i++ )
		b.insert ( arr[i] ) ;
	cout << "B-tree of order 5:" << endl ;
	b.show( ) ;
	b.del ( 22 ) ;
	b.del ( 11 ) ;
	cout << "\n\nB-tree after deletion of values:" << endl ;
	b.show( ) ;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-b-trees/">C++ program to implement B-Trees</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-b-trees/feed/</wfw:commentRss>
			<slash:comments>19</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to implement AVL Tree &#038; its Operations</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-avl-tree-its-operations/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-avl-tree-its-operations/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Wed, 02 Feb 2011 12:23:37 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[AVL trees]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[operations]]></category>
		<category><![CDATA[traversal]]></category>
		<category><![CDATA[Binary Search Tree]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1275</guid>

					<description><![CDATA[<p>#include #include #include #define FALSE 0 #define TRUE 1 struct AVLNode { int data ; int balfact ; AVLNode *left ; AVLNode *right ; } ; class avltree { private : AVLNode *root ; public : avltree( ) ; AVLNode* insert ( int data, int *h ) ; static AVLNode* buildtree ( AVLNode *root, int</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-avl-tree-its-operations/">C++ program to implement AVL Tree & its Operations</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
#include <stdlib.h>
#include<constream.h>
#define FALSE 0
#define TRUE 1
struct AVLNode
{
	int data ;
	int balfact ;
	AVLNode *left ;
	AVLNode *right ;
} ;

class avltree
{
	private :
		AVLNode *root ;
	public :
		avltree( ) ;
		AVLNode*  insert ( int data, int *h ) ;
		static AVLNode* buildtree ( AVLNode *root, int data, int *h ) ;
		void display( AVLNode *root ) ;
		AVLNode* deldata ( AVLNode* root, int data, int *h ) ;
		static AVLNode* del ( AVLNode *node, AVLNode* root, int *h ) ;
		static AVLNode* balright ( AVLNode *root, int *h ) ;
		static AVLNode* balleft ( AVLNode* root, int *h ) ;
		void setroot ( AVLNode *avl ) ;
		~avltree( ) ;
		static void deltree ( AVLNode *root ) ;
} ;
avltree :: avltree( )
{
	root = NULL ;
}
AVLNode* avltree :: insert ( int data, int *h )
{
	root = buildtree ( root, data, h ) ;
	return root ;
}
AVLNode* avltree :: buildtree ( AVLNode *root, int data, int *h )
{
	AVLNode *node1, *node2 ;

	if ( root == NULL )
	{
		root = new AVLNode ;
		root -> data = data ;
		root -> left = NULL ;
		root -> right = NULL ;
		root -> balfact = 0 ;
		*h = TRUE ;
		return ( root ) ;
	}
	if ( data < root -> data )
	{
		root -> left = buildtree ( root -> left, data, h ) ;

		// If left subtree is higher
		if ( *h )
		{
			switch ( root -> balfact )
			{
				case 1 :
					node1 = root -> left ;
					if ( node1 -> balfact == 1 )
					{
						cout << "\nRight rotation." ;
						root -> left = node1 -> right ;
						node1 -> right = root ;
						root -> balfact = 0 ;
						root = node1 ;
					}
					else
					{
						cout << "\nDouble rotation, left then right." ;
						node2 = node1 -> right ;
						node1 -> right = node2 -> left ;
						node2 -> left = node1 ;
						root -> left = node2 -> right ;
						node2 -> right = root ;
						if ( node2 -> balfact == 1 )
							root -> balfact = -1 ;
						else
							root -> balfact = 0 ;
						if ( node2 -> balfact == -1 )
							node1 -> balfact = 1 ;
						else
							node1 -> balfact = 0 ;
						root = node2 ;
					}
					root -> balfact = 0 ;
					*h = FALSE ;
					break ;

				case 0 :
					root -> balfact = 1 ;
					break ;
				case -1 :
					root -> balfact = 0 ;
					*h = FALSE ;
			}
		}
	}

	if ( data > root -> data )
	{
		root -> right = buildtree ( root -> right, data, h ) ;

		if ( *h )
		{
			switch ( root -> balfact )
			{
				case 1 :
					root -> balfact = 0 ;
					*h = FALSE ;
					break ;
				case 0 :
					root -> balfact = -1 ;
					break ;
				case -1 :
					node1 = root -> right ;
					if ( node1 -> balfact == -1 )
					{
						cout << "\nLeft rotation." ;
						root -> right = node1 -> left ;
						node1 -> left = root ;
						root -> balfact = 0 ;
						root = node1 ;
					}
					else
					{
						cout << "\nDouble rotation, right then left." ;
						node2 = node1 -> left ;
						node1 -> left = node2 -> right ;
						node2 -> right = node1 ;
						root -> right = node2 -> left ;
						node2 -> left = root ;
						if ( node2 -> balfact == -1 )
							root -> balfact = 1 ;
						else
							root -> balfact = 0 ;
						if ( node2 -> balfact == 1 )
							node1 -> balfact = -1 ;
						else
							node1 -> balfact = 0 ;
						root = node2 ;
					}
					root -> balfact = 0 ;
					*h = FALSE ;
			}
		}
	}
	return ( root ) ;
}
void avltree :: display ( AVLNode* root )
{
	if ( root != NULL )
	{
		display ( root -> left ) ;
		cout << root -> data << "\t" ;
		display ( root -> right ) ;
	}
}
AVLNode* avltree :: deldata ( AVLNode *root, int data, int *h )
{
	AVLNode *node ;
	if ( root -> data == 13 )
		cout << root -> data ;
	if ( root == NULL )
	{
		cout << "\nNo such data." ;
		return ( root ) ;
	}
	else
	{
		if ( data < root -> data )
		{
			root -> left = deldata ( root -> left, data, h ) ;
			if ( *h )
				root = balright ( root, h ) ;
		}
		else
		{
			if ( data > root -> data )
			{
				root -> right = deldata ( root -> right, data, h ) ;
				if ( *h )
					root = balleft ( root, h ) ;
			}
			else
			{
				node = root ;
				if ( node -> right == NULL )
				{
					root = node -> left ;
					*h = TRUE ;
					delete ( node ) ;
				}
				else
				{
					if ( node -> left == NULL )
					{
						root = node -> right ;
						*h = TRUE ;
						delete ( node ) ;
					}
					else
					{
						node -> right = del ( node -> right, node, h ) ;
						if ( *h )
							root = balleft ( root, h ) ;
					}
				}
			}
		}
	}
	return ( root ) ;
}
AVLNode* avltree :: del ( AVLNode *succ, AVLNode *node, int *h )
{
	AVLNode *temp = succ ;

	if ( succ -> left != NULL )
	{
		succ -> left = del ( succ -> left, node, h ) ;
		if ( *h )
			succ = balright ( succ, h ) ;
	}
	else
	{
		temp = succ ;
		node -> data = succ -> data ;
		succ = succ -> right ;
		delete ( temp ) ;
		*h = TRUE ;
	}
	return ( succ ) ;
}
AVLNode* avltree :: balright ( AVLNode *root, int *h )
{
	AVLNode *temp1, *temp2 ;
	switch ( root -> balfact )
	{
		case 1 :
			root -> balfact = 0 ;
			break ;
		case 0 :
			root -> balfact = -1 ;
			*h  = FALSE ;
			break ;
		case -1 :
			temp1 = root -> right ;
			if ( temp1 -> balfact <= 0 )
			{
				cout << "\nLeft rotation." ;
				root -> right = temp1 -> left ;
				temp1 -> left = root ;
				if ( temp1 -> balfact == 0 )
				{
					root -> balfact = -1 ;
					temp1 -> balfact = 1 ;
					*h = FALSE ;
				}
				else
				{
					root -> balfact = temp1 -> balfact = 0 ;
				}
				root = temp1 ;
			}
			else
			{
				cout << "\nDouble rotation, right then left." ;
				temp2 = temp1 -> left ;
				temp1 -> left = temp2 -> right ;
				temp2 -> right = temp1 ;
				root -> right = temp2 -> left ;
				temp2 -> left = root ;
				if ( temp2 -> balfact == -1 )
					root -> balfact = 1 ;
				else
					root -> balfact = 0 ;
				if ( temp2 -> balfact == 1 )
					temp1 -> balfact = -1 ;
				else
					temp1 -> balfact = 0 ;
				root = temp2 ;
				temp2 -> balfact = 0 ;
			}
	}
	return ( root ) ;
}
AVLNode* avltree :: balleft ( AVLNode *root, int *h )
{
	AVLNode *temp1, *temp2 ;
	switch ( root -> balfact )
	{
		case -1 :
			root -> balfact = 0 ;
			break ;

		case 0 :
			root -> balfact = 1 ;
			*h = FALSE ;
			break ;

		case 1 :
			temp1 = root -> left ;
			if ( temp1 -> balfact >= 0 )
			{
				cout << "\nRight rotation." ;
				root -> left = temp1 -> right ;
				temp1 -> right = root ;

				if ( temp1 -> balfact == 0 )
				{
					root -> balfact = 1 ;
					temp1 -> balfact = -1 ;
					*h = FALSE ;
				}
				else
				{
					root -> balfact = temp1 -> balfact = 0 ;
				}
				root = temp1 ;
			}
			else
			{
				cout << "\nDouble rotation, left then right." ;
				temp2 = temp1 -> right ;
				temp1 -> right = temp2 -> left ;
				temp2 -> left = temp1 ;
				root -> left = temp2 -> right ;
				temp2 -> right = root ;
				if ( temp2 -> balfact == 1 )
					root -> balfact = -1 ;
				else
					root -> balfact = 0 ;
				if ( temp2-> balfact == -1 )
					temp1 -> balfact = 1 ;
				else
					temp1 -> balfact = 0 ;
				root = temp2 ;
				temp2 -> balfact = 0 ;
			}
	}
	return ( root ) ;
}
void avltree :: setroot ( AVLNode *avl )
{
	root = avl ;
}
avltree :: ~avltree( )
{
	deltree ( root ) ;
}


void avltree :: deltree ( AVLNode *root )
{
	if ( root != NULL )
	{
		deltree ( root -> left ) ;
		deltree ( root -> right ) ;
	}
	delete ( root ) ;
}
void main( )
{
	avltree at ;
	AVLNode *avl = NULL ;
	int h ;
	clrscr();
	avl = at.insert ( 20, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 6, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 29, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 5, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 12, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 25, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 32, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 10, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 15, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 27, &h ) ;
	at.setroot ( avl ) ;
	avl = at.insert ( 13, &h ) ;
	at.setroot ( avl ) ;
	cout << endl << "AVL tree:\n" ;
	at.display ( avl ) ;
	avl = at.deldata ( avl, 20, &#038;h ) ;
	at.setroot ( avl ) ;
	avl = at.deldata ( avl, 12, &#038;h ) ;
	at.setroot ( avl ) ;
	cout << endl << "AVL tree after deletion of a node:\n" ;
	at.display ( avl ) ;
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-avl-tree-its-operations/">C++ program to implement AVL Tree & its Operations</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-avl-tree-its-operations/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to implement Binary Search Tree(BST) and its Operations</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-binary-search-treebst-and-its-operations/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-binary-search-treebst-and-its-operations/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Wed, 02 Feb 2011 12:21:33 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[traversal]]></category>
		<category><![CDATA[Binary Search Tree]]></category>
		<category><![CDATA[BST]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1273</guid>

					<description><![CDATA[<p>#include class btree { private : struct node { node *left ; char data ; node *right ; } *root ; char *arr ; int *lc ; int *rc ; public : btree ( char *a, int *l, int *r, int size ) ; void insert ( int index ) ; static node* buildtree (</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-binary-search-treebst-and-its-operations/">C++ program to implement Binary Search Tree(BST) and its Operations</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
class btree
{
	private :
		struct node
		{
			node *left ;
			char data ;
			node *right ;
		} *root ;
		char *arr ;
		int *lc ;
		int *rc ;
	public :
		btree ( char *a, int *l, int *r, int size ) ;
		void insert ( int index ) ;
		static node* buildtree ( char *a, int *l, int *r, int index ) ;
		void display( ) ;
		static void inorder ( node *sr ) ;
		~btree( ) ;
		static void del ( node *sr ) ;
} ;
btree :: btree ( char *a, int *l, int *r, int size )
{
	root = NULL ;
	arr = new char[size] ;
	lc = new int[size] ;
	rc = new int[size] ;
	for ( int i = 0 ; i < size ; i++ )
	{
		* ( arr + i ) = * ( a + i ) ;
		* ( lc + i ) = * ( l + i ) ;
		* ( rc + i ) = * ( r + i ) ;
	}
}
void btree :: insert ( int index )
{
	root = buildtree ( arr, lc, rc, index ) ;
}
node* btree :: buildtree ( char *a, int *l, int *r, int index )
{
	node *temp = NULL ;
	if ( index != -1 )
	{
		temp = new node ;
		temp -> left = buildtree ( a, l, r, * ( l + index ) ) ;
		temp -> data = * ( a + index ) ;
		temp -> right = buildtree ( a, l, r, * ( r + index ) ) ;
	}
	return temp ;
}
void btree :: display( )
{
	inorder ( root ) ;
}
void btree :: inorder ( node *sr )
{
	if ( sr != NULL )
	{
		inorder ( sr -> left ) ;
		cout << sr -> data << "\t" ;
		inorder ( sr -> right ) ;
	}
}
btree :: ~btree( )
{
	delete arr ;
	delete lc ;
	delete rc ;
	del ( root ) ;
}
void btree :: del ( node *sr )
{
	if ( sr != NULL )
	{
		del ( sr -> left ) ;
		del ( sr -> right ) ;
	}
	delete sr ;
}
void main( )
{
	char a[ ] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', '\0', '\0', 'H' } ;
	int  l[ ] = {  1,   3,   5,   -1,   9,  -1,  -1,   -1,   -1,  -1 } ;
	int  r[ ] = {  2,   4,   6,   -1,  -1,  -1,  -1,   -1,   -1,  -1 } ;
	int sz = sizeof ( a ) ;
	btree bt ( a, l, r, sz ) ;
	bt.insert( 0 ) ;
	cout << "\nIn-order Traversal: " << endl ;
	bt.display( ) ;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-binary-search-treebst-and-its-operations/">C++ program to implement Binary Search Tree(BST) and its Operations</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-binary-search-treebst-and-its-operations/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program for creation and traversal of a Binary Tree</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-for-creation-and-traversal-of-a-binary-tree/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-for-creation-and-traversal-of-a-binary-tree/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Wed, 02 Feb 2011 12:19:34 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[binary tree]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[traversal]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1271</guid>

					<description><![CDATA[<p>#include #include #include struct tree_node { tree_node *left; tree_node *right; int data; } ; class bst { tree_node *root; public: bst() { root=NULL; } int isempty() { return(root==NULL); } void insert(int item); void inordertrav(); void inorder(tree_node *); void postordertrav(); void postorder(tree_node *); void preordertrav(); void preorder(tree_node *); }; void bst::insert(int item) { tree_node *p=new tree_node;</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-for-creation-and-traversal-of-a-binary-tree/">C++ program for creation and traversal of a Binary Tree</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct tree_node
{
	tree_node *left;
	tree_node *right;
	int data;
} ;
class bst
{
	tree_node *root;
	public:
	bst()
	{
		root=NULL;
	}
	int isempty() 
	{
		return(root==NULL);
	}
	void insert(int item);
	void inordertrav();
	void inorder(tree_node *);
	void postordertrav();
	void postorder(tree_node *);
	void preordertrav();
	void preorder(tree_node *);
};
void bst::insert(int item)
{
	tree_node *p=new tree_node;
	tree_node *parent;
	p->data=item;
	p->left=NULL;
	p->right=NULL;
	parent=NULL;
	if(isempty())
		root=p;
	else
	{
		tree_node *ptr;
		ptr=root;
		while(ptr!=NULL)
		{
			parent=ptr;
			if(item>ptr->data)		
				ptr=ptr->right;
			else
				ptr=ptr->left;
		}	
		if(item<parent->data)
			parent->left=p;
		else
			parent->right=p;
	}
}
void bst::inordertrav()
{
	inorder(root);
}
void bst::inorder(tree_node *ptr)
{
	if(ptr!=NULL)
	{
		inorder(ptr->left);
		cout<<"  "<<ptr->data<<"     ";
		inorder(ptr->right);
	}
}
void bst::postordertrav()
{
	postorder(root);
}
void bst::postorder(tree_node *ptr)
{
	if(ptr!=NULL)
	{
		postorder(ptr->left);
		postorder(ptr->right);
		cout<<"  "<<ptr->data<<"     ";
	}
}
void bst::preordertrav()
{
	preorder(root);
}
void bst::preorder(tree_node *ptr)
{
	if(ptr!=NULL)
	{
		cout<<"  "<<ptr->data<<"     ";
		preorder(ptr->left);
		preorder(ptr->right);
	}
}
void main()
{
	bst b;
	b.insert(52);
	b.insert(25);
	b.insert(50);
	b.insert(15);
	b.insert(40);
	b.insert(45);
	b.insert(20); cout<<"inorder"<<endl;
	b.inordertrav();
	cout<<endl<<"postorder"<<endl;
	b.postordertrav();
	cout<<endl<<"preorder"<<endl;
	b.preordertrav();
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-for-creation-and-traversal-of-a-binary-tree/">C++ program for creation and traversal of a Binary Tree</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-for-creation-and-traversal-of-a-binary-tree/feed/</wfw:commentRss>
			<slash:comments>16</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to implement Queue using Linked Representation</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-linked-representation/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-linked-representation/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Mon, 31 Jan 2011 12:14:56 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[Linked Representation]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[linked list]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1267</guid>

					<description><![CDATA[<p>#include template class Node { friend LinkedQueue; private: T data; Node *link; }; template class LinkedQueue { public: LinkedQueue() {front = rear = 0;} // constructor ~LinkedQueue(); // destructor int IsEmpty() const {return ((front) ? 0 : 1);} T First() const; // return first element T Last() const; // return last element LinkedQueue&#038; Add(const T&</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-linked-representation/">C++ program to implement Queue using Linked Representation</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
template<class T>
class Node
{
	friend LinkedQueue<T>;
	private:
	T data;
	Node<T> *link;
};
template<class T>
class LinkedQueue {
	public:
		LinkedQueue() {front = rear = 0;} // constructor
		~LinkedQueue(); // destructor
		int IsEmpty() const
		{return ((front) ? 0 : 1);}
		T First() const; // return first element
		T Last() const; // return last element
		LinkedQueue<T>& Add(const T& x);
		LinkedQueue<T>& Delete(T& x);
	private:
		Node<T> *front;  // pointer to first node
		Node<T> *rear;   // pointer to last node
};

	template<class T>
LinkedQueue<T>::~LinkedQueue()
{// Queue destructor.  Delete all nodes.
	Node<T> *next;
	while (front) {
		next = front->link;
		delete front;
		front = next;
	}
}
template<class T>
T LinkedQueue<T>::First() const
{
	if (IsEmpty())   { cout<<"OutOfBounds()";  return -1; };
	return front->data;
}
template<class T>
T LinkedQueue<T>::Last() const
{
	if (IsEmpty()) { cout<<"OutOfBounds()";    return -1; };
	return rear->data;
}
	template<class T>
LinkedQueue<T>& LinkedQueue<T>::Add(const T& x)
{
	Node<T> *p = new Node<T>;
	p->data = x;
	p->link = 0;
	if (front) rear->link = p;  // queue not empty
	else front = p;             // queue empty
	rear = p;
	return *this;
}
	template<class T>
LinkedQueue<T>& LinkedQueue<T>::Delete(T& x)
{
	if (IsEmpty()) {  cout<<"OutOfBounds()"; return *this; };
	x = front->data;
	Node<T> *p = front;
	front = front->link;
	delete p;
	return *this;
}
void main(void)
{
	LinkedQueue<int> Q;
	int x;
	Q.Add(1).Add(2).Add(3).Add(4);
	cout << "No queue add failed" << endl;
	cout << "Queue is now 1234" << endl;
	Q.Delete(x);
	cout << "Deleted " << x << endl;
	cout << Q.First() << " is at front" << endl;
	cout << Q.Last() << " is at end" << endl;
	Q.Delete(x);
	cout << "Deleted " << x << endl;
	Q.Delete(x);
	cout << "Deleted " << x << endl;
	Q.Delete(x);
	cout << "Deleted " << x << endl;
	cout << "No queue delete failed " << endl;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-linked-representation/">C++ program to implement Queue using Linked Representation</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-linked-representation/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to implement Queue using Formula Based Representation</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-formula-based-representation/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-formula-based-representation/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Mon, 31 Jan 2011 12:03:38 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[Formula Based Representation]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1265</guid>

					<description><![CDATA[<p>#include #include class queue { private : int *arr ; int front, rear ; int MAX ; public : queue( int maxsize = 10 ) ; void addq ( int item ) ; int delq( ) ; } ; queue :: queue( int maxsize ) { MAX = maxsize ; arr = new int [</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-formula-based-representation/">C++ program to implement Queue using Formula Based Representation</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
#include <conio.h>
class queue
{
	private :

		int *arr ;
		int front, rear ;
		int MAX ;
	public :
		queue( int maxsize = 10 ) ;
		void addq ( int item ) ;
		int delq( ) ;
} ;
queue :: queue( int maxsize )
{
	MAX = maxsize ;
	arr = new int [ MAX ];
	front = -1 ;
	rear = -1 ;
}
void queue :: addq ( int item )
{
	if ( rear == MAX - 1 )
	{
		cout << "\nQueue is full" ;
		return ;
	}
	rear++ ;
	arr[rear] = item ;
	if ( front == -1 )
		front = 0 ;
}
int queue :: delq( )
{
	int data ;

	if ( front == -1 )
	{
		cout << "\nQueue is Empty" ;
		return NULL ;
	}

	data = arr[front] ;
	arr[front] = 0 ;
	if ( front == rear )
		front = rear = -1 ;
	else
		front++ ;

	return  data ;
}
void main( )
{
	queue a (10 ) ;
	clrscr();
	a.addq ( 23 ) ;
	a.addq ( 9 ) ;
	a.addq ( 11 ) ;
	a.addq ( -10 ) ;
	a.addq ( 25 ) ;
	a.addq ( 16 ) ;
	a.addq ( 17 ) ;
	a.addq ( 22 ) ;
	a.addq ( 19 ) ;
	a.addq ( 30 ) ;
	a.addq ( 32 ) ;
	int i = a.delq( ) ;
	cout << "\nItem deleted: " << i ;
	i = a.delq( ) ;
	cout << "\nItem deleted: " << i ;
	i = a.delq( ) ;
	cout << "\nItem deleted: " << i ;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-formula-based-representation/">C++ program to implement Queue using Formula Based Representation</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-queue-using-formula-based-representation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to implement Hash Table</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Mon, 31 Jan 2011 12:01:56 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[Hash Table]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1263</guid>

					<description><![CDATA[<p>#include #include #include template class HashTable { public: HashTable(int divisor = 11); ~HashTable() {delete [] ht; delete [] empty;} int Search(const K&#038; k, E&#038; e) const; HashTable&#038; Insert(const E&#038; e); void Output();// output the hash table void del(E e); private: int hSearch(const K&#038; k) const; int D; // hash function divisor E *ht; // hash</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/">C++ program to implement Hash Table</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
#include <stdlib.h>
#include<constream.h>
template<class E, class K>
class HashTable {
	public:
		HashTable(int divisor = 11);
		~HashTable() {delete [] ht;
			delete [] empty;}
			int Search(const K& k, E& e) const;
			HashTable<E,K>& Insert(const E& e);
			void Output();// output the hash table
			void del(E e);
	private:
			int hSearch(const K& k) const;
			int D; // hash function divisor
			E *ht; // hash table array
			int *empty; // 1D array
};
	template<class E, class K>
HashTable<E,K>::HashTable(int divisor)
{// Constructor.
	D = divisor;
	ht = new E [D];
	empty = new int [D];

	for (int i = 0; i < D; i++)
		empty[i] = 1;
}
template<class E, class K>
int HashTable<E,K>::hSearch(const K& k) const
{
	int i = k % D;  
	int j = i;     
	do {
		if (empty[j] || ht[j] == k) return j;
		j = (j + 1) % D;  // next bucket
	} while (j != i); // returned to home?
	return j;  // table full
}
	template<class E, class K>
void HashTable<E,K>::del(E e)
{
	int b=hSearch(e);
	if( !empty[b] && ht[b]==e)
	{
		ht[b]=0;
		empty[b]=1;
	}
	else
		cout<<"element not found";

}
template<class E, class K>
int HashTable<E,K>::Search(const K& k, E& e) const
{
	int b = hSearch(k);
	if (empty[b] || ht[b] != k) return 0;
	e = ht[b];
	return 1;
}
	template<class E, class K>
HashTable<E,K>& HashTable<E,K>::Insert(const E& e)
{// Hash table insert.
	K k = e; // extract key
	int b = hSearch(k);
	if (empty[b]) {empty[b] = 0;
		ht[b] = e;
		return *this;

	}
	if (ht[b] == k) { cout<<"bad input"; return *this; } // duplicate
	cout<<"No memory";// table full
	return *this;
}

	template<class E, class K>
void HashTable<E,K>::Output()
{
	cout<<endl;
	for (int i = 0; i< D; i++) {
		if (empty[i]) cout << "0 ";
		else cout << ht[i]<<" ";}
	cout<<endl;
}
class element {
	friend void main(void);
	public:
	operator long() const {return key;}
	private:
	int data;
	long key;
};
void main(void)
{
	clrscr();
	HashTable<int , int > h(11);
	int e;
	e = 80;
	h.Insert(e);
	e = 40;
	h.Insert(e);
	e = 65;
	h.Insert(e);
	cout<<"After inserting 80,40,65:";
	h.Output();
	cout<<endl;
	h.del(40);
	cout<<"After deleting 40:";
	h.Output();
	cout<<endl;
	e = 58;
	h.Insert(e);
	e = 24;
	h.Insert(e);
	cout<<"after appending 58, 24:";
	h.Output();
	cout<<"Trying to delete element 25:";
	h.del(25);
	h.Output();
	e = 2;
	h.Insert(e);
	e = 13;
	h.Insert(e);
	e = 46;
	h.Insert(e);
	e = 16;
	h.Insert(e);
	e = 7;
	h.Insert(e);
	e = 21;
	h.Insert(e);
	h.Insert(10);
	cout <<"After inserting more values:" << endl;
	h.Output();
	e = 99;
	cout<<"trying to insert 99:";
	h.Insert(e);
	h.Output();
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/">C++ program to implement Hash Table</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-hash-table/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Program to represent Indirect Addressing of Linear List using Templates</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Sat, 29 Jan 2011 10:49:31 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[linear list]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[Indirect Addressing]]></category>
		<category><![CDATA[indirect list]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1218</guid>

					<description><![CDATA[<p>IndirectList(int MaxLinearSize=10);<br />
~IndirectList();//destructor<br />
int IsEmpty()const{return length==0;}<br />
int Length()const{return length;}<br />
int Find(int k,T&#038;x)const;<br />
int Search(const T&#038;x)const;<br />
void Delete(int k,T&#038;x);<br />
void Insert(int k,const T&#038;x);<br />
void Output()const;</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/">Program to represent Indirect Addressing of Linear List using Templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include<iostream.h>
#include<constream.h>
template<class T>
class IndirectList
{
	private:
		int length;
		int MaxSize;
		T**table; 
	public:
		IndirectList(int MaxLinearSize=10);  	
		~IndirectList();//destructor
		int IsEmpty()const{return length==0;}
		int Length()const{return length;}
		int Find(int k,T&x)const;
		int Search(const T&x)const;
		void Delete(int k,T&x);

		void Insert(int k,const T&x);

		void Output()const;
};
	template<class T>
IndirectList<T>::IndirectList(int MaxListSize)
{
	MaxSize=MaxListSize;
	table=new T*[MaxSize];
	length=0;
}
	template<class T>
IndirectList<T>::~IndirectList()
{
	for(int i=0;i<length;i++)
		delete table[i];
	delete[]table;
}
template<class T>
int IndirectList<T>::Find(int k,T&x)const
{
	if(k<1||k>length)
		return 0; //no kth element
	if(x==*table[k-1])
		return 1;
	else
		return 0;
}
template<class T>
int IndirectList<T>::Search(const T&x)const
{
	for(int i=0;i<length;i++)
		if(*table[i]==x)
			return ++i;
	return 0;
}
	template<class T>
void IndirectList<T>::Delete(int k,T&x)
{
	if(Find(k,x))
	{
		for(int i=k;i<length;i++)
			table[i-1]=table[i];
		length--;
	}
	else
		cout<<"out of bounds\n";
}
	template<class T>
void IndirectList<T>::Insert(int k,const T&x)
{
	if(k<0||k>length)
		cout<<"out of bounds\n";
	if(length==MaxSize)
		cout<<"no memory\n";
	for(int i=length-1;i>=k;i--)
		table[i+1]=table[i];
	table[k]=new T;
	*table[k]=x;
	length++;
}
template<class T>
void IndirectList<T>::Output()const
{
	if(IsEmpty())
		cout<<"list is empty\n";
	else
		for(int i=0;i<length;i++)
			cout<<*table[i]<<"\t";
}
void menu()
{
	cout<<"\n MENU\n";
	cout<<"1.Length\n";
	cout<<"2.Find\n";
	cout<<"3.Search\n";
	cout<<"4.Delete\n";
	cout<<"5.Insert\n";
	cout<<"6.Output\n";
}
void main()
{
	int choice;
	int k,x,len,p;
	clrscr();
	IndirectList<int>obj;
	do
	{
		menu();
		cout<<"enter choice\n";
		cin>>choice;
		switch(choice)
		{
			case 1:
				len=obj.Length();
				if(len==0)
					cout<<"List is empty\n";
				else
					cout<<"length of Indirectlist is "<<len<<endl;
				break;
			case 2:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				p=obj.Find(k,x);
				if(p==1)
					cout<<"found"<<endl;
				if(p==0)
					cout<<"not found"<<endl;
				break;
			case 3:
				cout<<"enter x(value)\n";
				cin>>x;
				p=obj.Search(x);
				if(p)
					cout<<"searching is sucessful and found at "<<p<<endl;
				else
					cout<<"searching not sucessful"<<endl;
				break;
			case 4:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				obj.Delete(k,x);
				break;
			case 5:
				cout<<"enter k,x(index and value)\n";
				cin>>k>>x;
				obj.Insert(k,x);
				break;
			case 6:
				cout<<"elements in the list are:\n\n";
				obj.Output();
				break;
			default:
				cout<<"invalid choice\n";
		}
	}
	while(choice>=1&&choice<=6);
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/">Program to represent Indirect Addressing of Linear List using Templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Program to implement linked representation of Linear list using templates</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 28 Jan 2011 10:47:11 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[linear list]]></category>
		<category><![CDATA[array]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1214</guid>

					<description><![CDATA[<p>#include #include #include template class ChainNode { friend Chain; private: T data; ChainNode*link; }; template class Chain { private: ChainNode*first; public: Chain() { first=0; } ~Chain(); int IsEmpty()const; int Length()const; int Find(int k,T&#038;x); int Search(const T&#038;x); void Delete(int k,T&#038;x); void Insert(int k,const T&#038;x); void Output(); }; template Chain::~Chain() { ChainNode*next; while(first) { next=first->link; delete first;</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/">Program to implement linked representation of Linear list using templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include<iostream.h>
#include<constream.h>
#include<stdlib.h>
template<class T>
class ChainNode
{
	friend Chain<T>;
	private:
	T data;
	ChainNode<T>*link;
};
template<class T>
class Chain
{
	private:
		ChainNode<T>*first; 
	public:
		Chain()
		{
			first=0;
		}
		~Chain();
		int IsEmpty()const;
		int Length()const;
		int Find(int k,T&x);
		int Search(const T&x);
		void Delete(int k,T&x);
		void Insert(int k,const T&x);
		void Output();
};
	template<class T>
Chain<T>::~Chain()
{
	ChainNode<T>*next;
	while(first)
	{
		next=first->link;
		delete first;
		first=next;
	}
}
template<class T>
int Chain<T>::Length()const
{
	ChainNode<T>*current=first;
	int len=0;
	while(current)
	{
		current=current->link;
		len++;
	}
	return len;
}
	template<class T>
int Chain<T>::Find(int k,T&x)
	//set x to the kth element in the chain
	//return 0 if no kth element, return 1 otherwise
{
	if(k<1)
		return 0;
	ChainNode<T>*current=first;
	int index=1; //index of current
	while(index<k&#038;&#038;current)
	{
		current=current->link;
		index++;
	}
	if(current&&x==current->data)
		return 1;
	else
		return 0; //no kth element
}
	template<class T>
int Chain<T>::Search(const T&x)
{
	ChainNode<T>*current=first;
	int index=1; //index of current
	while(current&&current->data!=x)
	{
		current=current->link;
		index++;
	}
	if(current)
	{
		return index;
	}
	else
		return 0;
}
	template<class T>
void Chain<T>::Delete(int k,T&x)
{
	if(k<1||!first)
		cout<<"out of bounds\n"; //no kth element
	ChainNode<T>*p=first;
	if(k==1) //p is already at k
		first=first->link; //remove
	else
	{
		ChainNode<T>*q=first;
		for(int index=1;index<k-1&#038;&q;index++)
		{
			q=q->link;
		}
		if(!q||!q->link)
			cout<<"the element doesnot exist\n";
		p=q->link;
		q->link=p->link; //remove from linked list
		//free node p
		delete p;
	}

}
	template<class T>
void Chain<T>::Insert(int k,const T&x)
{
	if(k<0)
		cout<<"out of bounds\n"; //no kth element
	//p will be eventually to kth node
	ChainNode<T>*p=first;
	for(int index=1;index<k&#038;&p;index++)
		p=p->link;
	if(k>0&&!p)
		cout<<"out of bounds\n"; //no kth element
	ChainNode<T>*y=new ChainNode<T>;
	y->data=x;
	if(k)
	{
		//insert after p
		y->link=p->link;
		p->link=y;
	}
	else
	{
		y->link=first;
		first=y;
	}
}
	template<class T>
void Chain<T>::Output()
{
	ChainNode<T>*p=first;
	while(p)
	{
		cout<<p->data<<"\t";
		p=p->link;
	}
}


void menu()
{
	cout<<"\n MENU\n";
	cout<<"1.Length\n";
	cout<<"2.Find\n";
	cout<<"3.Search\n";
	cout<<"4.Delete\n";
	cout<<"5.Insert\n";
	cout<<"6.Output\n";
}
void main()
{
	int choice;
	int k,x,len,p;
	clrscr();
	Chain<int>obj;
	do
	{
		menu();
		cout<<"enter choice\n";
		cin>>choice;
		switch(choice)
		{
			case 1:
				len=obj.Length();
				if(len==0)
					cout<<"List is empty\n";
				else
					cout<<"length of linkedlist is "<<len<<endl;
				break;
			case 2:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				p=obj.Find(k,x);
				if(p==1)
					cout<<"found"<<endl;
				if(p==0)
					cout<<"not found"<<endl;
				break;
			case 3:
				cout<<"enter x(value)\n";
				cin>>x;
				p=obj.Search(x);
				if(p)
					cout<<"searching is sucessful and found at "<<p<<endl;
				else
					cout<<"searching not sucessful"<<endl;
				break;
			case 4:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				obj.Delete(k,x);
				break;
			case 5:
				cout<<"enter k,x(index and value)\n";
				cin>>k>>x;
				obj.Insert(k,x);
				break;
			case 6:
				cout<<"elements in the list are:\n\n";
				obj.Output();
				break;
			default:
				cout<<"invalid choice\n";
		}
	}
	while(choice>=1&&choice<=6);
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/">Program to implement linked representation of Linear list using templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
