<?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>Data structure | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/data-structure/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:58 +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 which converts given expression into its post-fix format</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-which-converts-given-expression-into-its-post-fix-format/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-which-converts-given-expression-into-its-post-fix-format/#comments</comments>
		
		<dc:creator><![CDATA[Drithi]]></dc:creator>
		<pubDate>Thu, 07 Jun 2012 09:15:38 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[Data structure]]></category>
		<category><![CDATA[postfix expression]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=3149</guid>

					<description><![CDATA[<p>Below C program converts a given expression into its post-fix format #include #include #include char s[20]; int top=-1; void main() { char str[20]; char ch; int i; char pop(); void push(char); int precd(char); s[top]='#'; clrscr(); printf("\n\t\tOUTPUT"); printf("\n\tEnter the expression:"); gets(str); printf("\n\tpostfix notation:"); for(i=0;str[i]!='\0';i++) { if(isalpha(str[i])) { printf("%c",str[i]); continue; } if(str[i]==')') { while((ch=pop())!='(') printf("%c",ch); } else</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-which-converts-given-expression-into-its-post-fix-format/">C program which converts given expression into its post-fix format</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Below C program converts a given expression into its post-fix format</p>
<pre lang="c" line="1">
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
char s[20];
int top=-1;
void main()
{
    char str[20];
    char ch;
    int i;
    char pop();
    void push(char);
    int precd(char);
    s[top]='#';
    clrscr();
    printf("\n\t\tOUTPUT");
    printf("\n\tEnter the expression:");
    gets(str);
    printf("\n\tpostfix notation:");
    for(i=0;str[i]!='\0';i++)
    {
        if(isalpha(str[i]))
        {
            printf("%c",str[i]);
            continue;
        }
        if(str[i]==')')
        {
            while((ch=pop())!='(')
                printf("%c",ch);
        }
        else if(str[i]=='(')
            push(str[i]);
        else if(precd(str[i])<=precd(s[top]))
        {
            printf("%c",pop());
            push(str[i]);
        }
        else
            push(str[i]);
    }
    while(top>=0)
        printf("%c",pop());
    getch();
}
void push(char st)
{
    s[++top]=st;
}
char pop()
{
    char st;
    st=s[top--];
    return(st);
}

int precd(char s)
{
    switch(s)
    {
    case '$':return(4);
    case '*':
    case '/': return(3);
    case '+':
    case '-': return(2);
    case '(': return(1);
    case '#': return(-1);
    }
    return(0);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-which-converts-given-expression-into-its-post-fix-format/">C program which converts given expression into its post-fix format</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-which-converts-given-expression-into-its-post-fix-format/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>C program to implement Circular Queue operations</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-to-implement-circular-queue-operations/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-to-implement-circular-queue-operations/#comments</comments>
		
		<dc:creator><![CDATA[Drithi]]></dc:creator>
		<pubDate>Wed, 06 Jun 2012 09:15:39 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[Data structure]]></category>
		<category><![CDATA[circular queue]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=3139</guid>

					<description><![CDATA[<p>Below C program implements various Circular Queue operations #include #define max 3 int q[10],front=0,rear=-1; void main() { int ch; void insert(); void delet(); void display(); clrscr(); printf("\nCircular Queue operations\n"); printf("1.insert\n2.delete\n3.display\n4.exit\n"); while(1) { printf("Enter your choice:"); scanf("%d",&#038;ch); switch(ch) { case 1: insert(); break; case 2: delet(); break; case 3:display(); break; case 4:exit(); default:printf("Invalid option\n"); } }</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-to-implement-circular-queue-operations/">C program to implement Circular Queue operations</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Below C program implements various Circular Queue operations</p>
<pre lang="c" line="1">
#include<stdio.h>
#define max 3
int q[10],front=0,rear=-1;
void main()
{
    int ch;
    void insert();
    void delet();
    void display();
    clrscr();
    printf("\nCircular Queue operations\n");
    printf("1.insert\n2.delete\n3.display\n4.exit\n");
    while(1)
    {
        printf("Enter your choice:");
        scanf("%d",&ch);
        switch(ch)
        {
        case 1: insert();
            break;
        case 2: delet();
            break;
        case 3:display();
            break;
        case 4:exit();
        default:printf("Invalid option\n");
        }
    }
}

void insert()
{
    int x;
    if((front==0&&rear==max-1)||(front>0&&rear==front-1))
        printf("Queue is overflow\n");
    else
    {
        printf("Enter element to be insert:");
        scanf("%d",&x);
        if(rear==max-1&&front>0)
        {
            rear=0;
            q[rear]=x;
        }
        else
        {
            if((front==0&&rear==-1)||(rear!=front-1))
                q[++rear]=x;
        }
    }
}
void  delet()
{
    int a;
    if((front==0)&&(rear==-1))
    {
        printf("Queue is underflow\n");
        getch();
        exit();
    }
    if(front==rear)
    {
        a=q[front];
        rear=-1;
        front=0;
    }
    else
        if(front==max-1)
        {
            a=q[front];
            front=0;
        }
        else a=q[front++];
        printf("Deleted element is:%d\n",a);
}

void display()
{
    int i,j;
    if(front==0&&rear==-1)
    {
        printf("Queue is underflow\n");
        getch();
        exit();
    }
    if(front>rear)
    {
        for(i=0;i<=rear;i++)
            printf("\t%d",q[i]);
        for(j=front;j<=max-1;j++)
            printf("\t%d",q[j]);
        printf("\nrear is at %d\n",q[rear]);
        printf("\nfront is at %d\n",q[front]);
    }
    else
    {
        for(i=front;i<=rear;i++)
        {
            printf("\t%d",q[i]);
        }
        printf("\nrear is at %d\n",q[rear]);
        printf("\nfront is at %d\n",q[front]);
    }
    printf("\n");
}
getch();
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-to-implement-circular-queue-operations/">C program to implement Circular Queue operations</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-circular-queue-operations/feed/</wfw:commentRss>
			<slash:comments>12</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[linked list]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[AVL trees]]></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[binary tree]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[traversal]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[C Programs]]></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[C Programs]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[Linked Representation]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[Queue]]></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>C++ program that uses dynamic programming algorithm to solve the optimal binary search tree problem</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-that-uses-dynamic-programming-algorithm-to-solve-the-optimal-binary-search-tree-problem/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-that-uses-dynamic-programming-algorithm-to-solve-the-optimal-binary-search-tree-problem/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Thu, 11 Mar 2010 17:39:44 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[binary tree]]></category>
		<category><![CDATA[optimal binary search tree]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1042</guid>

					<description><![CDATA[<p>/* Write a C++ program that uses dynamic programming algorithm to solve the optimal binary search tree problem */ #include #include #include using namespace std; #define MAX 10 int find(int i,int j); void print(int,int); int p[MAX],q[MAX],w[10][10],c[10][10],r[10][10],i,j,k,n,m; char idnt[7][10]; main() { cout >n; cout</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-that-uses-dynamic-programming-algorithm-to-solve-the-optimal-binary-search-tree-problem/">C++ program that uses dynamic programming algorithm to solve the optimal binary search tree problem</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>/* Write a C++ program that uses dynamic programming algorithm to solve the optimal binary search tree problem */</p>
<pre lang="cpp">
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
#define MAX 10
int find(int i,int j);
void print(int,int);
int p[MAX],q[MAX],w[10][10],c[10][10],r[10][10],i,j,k,n,m;
char idnt[7][10];

main()
{
	cout << "enter the no, of identifiers";
	cin >>n;
	cout <<"enter identifiers";
	for(i=1;i<=n;i++)
	gets(idnt[i]);
	cout <<"enter success propability for identifiers";
	for(i=1;i<=n;i++)
		cin >>p[i];
	cout << "enter failure propability for identifiers";
	for(i=0;i<=n;i++)
		cin >> q[i];
	for(i=0;i<=n;i++)
	{
		w[i][i]=q[i];
		c[i][i]=r[i][i]=0;
		w[i][i+1]=q[i]+q[i+1]+p[i+1];
		r[i][i+1]=i+1;
		c[i][i+1]=q[i]+q[i+1]+p[i+1];
	}
	w[n][n]=q[n];
	r[n][n]=c[n][n]=0;
	for(m=2;m<=n;m++)
	{
		for(i=0;i<=n-m;i++)
		{
		     j=i+m;
		     w[i][j]=w[i][j-1]+p[j]+q[j];
		     k=find(i,j);
		     r[i][j]=k;
		     c[i][j]=w[i][j]+c[i][k-1]+c[k][j];
		}
	}
       cout <<"\n";
       print(0,n); }

int find(int i,int j)
{
int min=2000,m,l;
for(m=i+1;m<=j;m++)
if(c[i][m-1]+c[m][j]<min)
{
min=c[i][m-1]+c[m][j];
l=m;
}
return l;
}
void print(int i,int j)
{
if(i<j)
puts(idnt[r[i][j]]);
else
return;
print(i,r[i][j]-1);
print(r[i][j],j);
}
</pre>
<p><strong>OUTPUT</strong></p>
<p>enter the no, of identifiers4<br />
enter identifiers<br />
do<br />
if<br />
int<br />
while<br />
enter success propability for identifiers3 3 1 1<br />
enter failure propability for identifiers2 3 1 1 1</p>
<p>tree in preorder form<br />
if<br />
do<br />
int<br />
while</p><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-that-uses-dynamic-programming-algorithm-to-solve-the-optimal-binary-search-tree-problem/">C++ program that uses dynamic programming algorithm to solve the optimal binary search tree problem</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-that-uses-dynamic-programming-algorithm-to-solve-the-optimal-binary-search-tree-problem/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
