<?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>C Programs | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/c/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 17:07:15 +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 for Simple DSC order Priority QUEUE Implementation using Structure</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-for-simple-dsc-order-priority-queue-implementation-using-structure-2/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-for-simple-dsc-order-priority-queue-implementation-using-structure-2/#respond</comments>
		
		<dc:creator><![CDATA[Ansten Lobo]]></dc:creator>
		<pubDate>Sat, 09 Jun 2012 17:07:15 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[structure]]></category>
		<category><![CDATA[Priority QUEUE]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=3335</guid>

					<description><![CDATA[<p>C Program for Simple DSC order Priority QUEUE Implementation using Structure. Source: Dr. G T Raju, Professor &#038; Head, Dept. of CSE, RNSIT #define SIZE 5 /* Size of Queue */ int f=0,r=-1; /* Global declarations */ typedef struct PRQ { int ele; int pr; }PriorityQ; PriorityQ PQ[SIZE]; PQinsert(int elem, int pre) { int i;</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-for-simple-dsc-order-priority-queue-implementation-using-structure-2/">C Program for Simple DSC order Priority QUEUE Implementation using Structure</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>C Program for Simple DSC order Priority QUEUE Implementation using Structure.<br />
Source: Dr. G T Raju, Professor &#038; Head, Dept. of CSE, RNSIT</p>
<pre lang="C" line="1">
#define SIZE 5            /* Size of Queue */
int f=0,r=-1;       /* Global declarations */
typedef struct PRQ
{
    int ele;
    int pr;
}PriorityQ;

PriorityQ PQ[SIZE];

PQinsert(int elem, int pre)
{
    int i;       /* Function for Insert operation */
    if( Qfull()) printf("\n\n Overflow!!!!\n\n");
    else
    {
        i=r;
        ++r;
        while(PQ[i].pr <= pre &#038;&#038; i >= 0) /* Find location for new elem */
        {
            PQ[i+1]=PQ[i];
            i--;
        }
        PQ[i+1].ele=elem;
        PQ[i+1].pr=pre;
    }
}

PriorityQ PQdelete()
{                      /* Function for Delete operation */
    PriorityQ p;
    if(Qempty()){ printf("\n\nUnderflow!!!!\n\n");
    p.ele=-1;p.pr=-1;
    return(p); }
    else
    {
        p=PQ[f];
        f=f+1;
        return(p);
    }
}
int Qfull()
{                     /* Function to Check Queue Full */
    if(r==SIZE-1) return 1;
    return 0;
}

int Qempty()
{                    /* Function to Check Queue Empty */
    if(f > r) return 1;
    return 0;
}

display()
{                  /* Function to display status of Queue */
    int i;
    if(Qempty()) printf(" \n Empty Queue\n");
    else
    {
        printf("Front->");
        for(i=f;i<=r;i++)
            printf("[%d,%d] ",PQ[i].ele,PQ[i].pr);
        printf("<-Rear");
    }
}

main()
{                         /* Main Program */
    int opn;
    PriorityQ p;
    do
    {
        clrscr();
        printf("\n ### Priority Queue Operations(DSC order) ### \n\n");
        printf("\n Press 1-Insert, 2-Delete,3-Display,4-Exit\n");
        printf("\n Your option ? ");
        scanf("%d",&#038;opn);
        switch(opn)
        {
        case 1: printf("\n\nRead the element and its Priority?");
            scanf("%d%d",&#038;p.ele,&#038;p.pr);
            PQinsert(p.ele,p.pr); break;
        case 2: p=PQdelete();
            if( p.ele != -1)
                printf("\n\nDeleted Element is %d \n",p.ele);
            break;
        case 3: printf("\n\nStatus of Queue\n\n");
            display(); break;
        case 4: printf("\n\n Terminating \n\n"); break;
        default: printf("\n\nInvalid Option !!! Try Again !! \n\n");
            break;
        }
        printf("\n\n\n\n  Press a Key to Continue . . . ");
        getch();
    }while(opn != 4);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-for-simple-dsc-order-priority-queue-implementation-using-structure-2/">C Program for Simple DSC order Priority QUEUE Implementation using Structure</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-for-simple-dsc-order-priority-queue-implementation-using-structure-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>C Program to convert Prefix Expression into INFIX</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/c-advanced/c-program-to-convert-prefix-expression-into-infix/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/c-advanced/c-program-to-convert-prefix-expression-into-infix/#comments</comments>
		
		<dc:creator><![CDATA[Ansten Lobo]]></dc:creator>
		<pubDate>Sat, 09 Jun 2012 16:58:41 +0000</pubDate>
				<category><![CDATA[Advanced programs]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[Prefix into INFIX]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=3323</guid>

					<description><![CDATA[<p>C Program to convert Prefix Expression into INFIX. Source: Dr. G T Raju, Professor &#038; Head, Dept. of CSE, RNSIT #include #include char opnds[50][80],oprs[50]; int topr=-1,topd=-1; pushd(char *opnd) { strcpy(opnds[++topd],opnd); } char *popd() { return(opnds[topd--]); } pushr(char opr) { oprs[++topr]=opr; } char popr() { return(oprs[topr--]); } int empty(int t) { if( t == 0) return(1);</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/c-advanced/c-program-to-convert-prefix-expression-into-infix/">C Program to convert Prefix Expression into INFIX</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>C Program to convert Prefix Expression into INFIX.<br />
Source: Dr. G T Raju, Professor &#038; Head, Dept. of CSE, RNSIT</p>
<pre lang="C" line="1">
#include <string.h>
#include <ctype.h>
char opnds[50][80],oprs[50];
int  topr=-1,topd=-1;
pushd(char *opnd)
{
    strcpy(opnds[++topd],opnd);
}
char *popd()
{
    return(opnds[topd--]);
}

pushr(char opr)
{
    oprs[++topr]=opr;
}
char popr()
{
    return(oprs[topr--]);
}
int empty(int t)
{
    if( t == 0) return(1);
    return(0);
}

main()
{
    char prfx[50],ch,str[50],opnd1[50],opnd2[50],opr[2];
    int i=0,k=0,opndcnt=0;
    gets(prfx);
    printf(" Given Prefix Expression : %s\n",prfx);
    while( (ch=prfx[i++]) != '\0')
    {
        if(isalnum(ch))
        {
            str[0]=ch; str[1]='\0';
            pushd(str); opndcnt++;
            if(opndcnt >= 2)
            {
                strcpy(opnd2,popd());
                strcpy(opnd1,popd());
                strcpy(str,"(");
                strcat(str,opnd1);
                ch=popr();
                opr[0]=ch;opr[1]='\0';
                strcat(str,opr);
                strcat(str,opnd2);
                strcat(str,")");
                pushd(str);
                opndcnt-=1;
            }
        }
        else
        {
            pushr(ch);
            if(opndcnt==1)opndcnt=0;  /* operator followed by single operand*/
        }
    }
    if(!empty(topd))
    {
        strcpy(opnd2,popd());
        strcpy(opnd1,popd());
        strcpy(str,"(");
        strcat(str,opnd1);
        ch=popr();
        opr[0]=ch;opr[1]='\0';
        strcat(str,opr);
        strcat(str,opnd2);
        strcat(str,")");
        pushd(str);
    }
    printf(" Infix Expression: ");
    puts(opnds[topd]);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/c-advanced/c-program-to-convert-prefix-expression-into-infix/">C Program to convert Prefix Expression into INFIX</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/c-advanced/c-program-to-convert-prefix-expression-into-infix/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>C Program for Infix to Prefix Conversion</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-for-infix-to-prefix-conversion/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-for-infix-to-prefix-conversion/#comments</comments>
		
		<dc:creator><![CDATA[Ansten Lobo]]></dc:creator>
		<pubDate>Sat, 09 Jun 2012 16:57:15 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[Source Codes]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[Infix to Prefix]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=3321</guid>

					<description><![CDATA[<p>C Program for Infix to Prefix Conversion. Source: Dr. G T Raju, Professor &#038; Head, Dept. of CSE, RNSIT #define SIZE 50 /* Size of Stack */ #include #include char s[SIZE]; int top=-1; /* Global declarations */ push(char elem) { /* Function for PUSH operation */ s[++top]=elem; } char pop() { /* Function for POP</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-for-infix-to-prefix-conversion/">C Program for Infix to Prefix Conversion</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>C Program for Infix to Prefix Conversion.<br />
Source: Dr. G T Raju, Professor &#038; Head, Dept. of CSE, RNSIT</p>
<pre lang="C" line="1">
#define SIZE 50            /* Size of Stack */
#include<string.h>
#include <ctype.h>
char s[SIZE];
int top=-1;       /* Global declarations */

push(char elem)
{                       /* Function for PUSH operation */
    s[++top]=elem;
}

char pop()
{                      /* Function for POP operation */
    return(s[top--]);
}

int pr(char elem)
{                 /* Function for precedence */
    switch(elem)
    {
    case '#': return 0;
    case ')': return 1;
    case '+':
    case '-': return 2;
    case '*':
    case '/': return 3;
    }
}

main()
{                         /* Main Program */
    char infx[50],prfx[50],ch,elem;
    int i=0,k=0;
    printf("\n\nRead the Infix Expression ? ");
    scanf("%s",infx);
    push('#');
    strrev(infx);
    while( (ch=infx[i++]) != '\0')
    {
        if( ch == ')') push(ch);
        else
            if(isalnum(ch)) prfx[k++]=ch;
            else
                if( ch == '(')
                {
                    while( s[top] != ')')
                        prfx[k++]=pop();
                    elem=pop(); /* Remove ) */
                }
                else
                {       /* Operator */
                    while( pr(s[top]) >= pr(ch) )
                        prfx[k++]=pop();
                    push(ch);
                }
    }
    while( s[top] != '#')     /* Pop from stack till empty */
        prfx[k++]=pop();
    prfx[k]='\0';          /* Make prfx as valid string */
    strrev(prfx);
    strrev(infx);
    printf("\n\nGiven Infix Expn: %s  Prefix Expn: %s\n",infx,prfx);
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/data-structures-c/c-program-for-infix-to-prefix-conversion/">C Program for Infix to Prefix Conversion</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-for-infix-to-prefix-conversion/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to implement stack using Linked List</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-linked-list/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-linked-list/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Thu, 03 Feb 2011 10:50:47 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[Linked Lists]]></category>
		<category><![CDATA[struct]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1252</guid>

					<description><![CDATA[<p>#include template class Node { friend LinkedStack; private: T data; Node *link; }; template class LinkedStack { public: LinkedStack() {top = 0;} ~LinkedStack(); int IsEmpty() const {return top == 0;} T Top() const; LinkedStack&#038; Add(const T&#038; x); LinkedStack&#038; Delete(T&#038; x); private: Node *top; }; template LinkedStack::~LinkedStack() {// Stack destructor.. Node *next; while (top) { next</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-linked-list/">C++ program to implement stack using Linked List</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 LinkedStack<T>;
	private:
	T data;
	Node<T> *link;
};
template<class T>
class LinkedStack {
	public:
		LinkedStack() {top = 0;}
		~LinkedStack();
		int IsEmpty() const {return top == 0;}
		T Top() const;
		LinkedStack<T>& Add(const T& x);
		LinkedStack<T>& Delete(T& x);
	private:
		Node<T> *top; 
};
	template<class T>
LinkedStack<T>::~LinkedStack()
{// Stack destructor..
	Node<T> *next;
	while (top) {
		next = top->link;
		delete top;
		top = next;
	}
}
template<class T>
T LinkedStack<T>::Top() const
{// Return top element.
	if (IsEmpty()) cout<<"Stack empty:";
	else
		return top->data;
}
	template<class T>
LinkedStack<T>& LinkedStack<T>::Add(const T& x)
{// Add x to stack.
	Node<T> *p = new Node<T>;
	p->data = x;
	p->link = top;
	top = p;
	return *this;
}
	template<class T>
LinkedStack<T>& LinkedStack<T>::Delete(T& x)
{// Delete top element and put it in x.
	if (IsEmpty()) 
	{
		cout<<"Stack empty";
		return *this;
	}
	x = top->data;
	Node<T> *p = top;
	top = top->link;
	delete p;
	return *this;
}
void main(void)
{
	int x;
	LinkedStack<int> S;
	S.Add(1).Add(2).Add(3).Add(4);
	cout << "Stack should be 1234" << endl;
	cout << "Stack top is " << S.Top() << endl;
	S.Delete(x);
	cout << "Deleted " << x << endl;
	S.Delete(x);
	cout << "Deleted " << x << endl;
	S.Delete(x);
	cout << "Deleted " << x << endl;
	S.Delete(x);
	cout << "Deleted " << x << endl;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-linked-list/">C++ program to implement stack using Linked List</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-stack-using-linked-list/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to implement Stack using Formula Based Representation</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-formula-based-representation/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-formula-based-representation/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Thu, 03 Feb 2011 10:47:47 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[Linked Lists]]></category>
		<category><![CDATA[Formula Based Representation]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1250</guid>

					<description><![CDATA[<p>#include #include template class Stack { public: Stack(int MaxStackSize); ~Stack(){delete[] S;} int IsEmpty()const{return top==-1;} int IsFull()const{return top==MaxTop;} T Peek()const; void Push(T); T Pop(); void Display(); private: int top; //current top of stack int MaxTop; //max val for top T *S; //element array }; template Stack::Stack(int MaxStackSize) { //stack constructor MaxTop=MaxStackSize-1; S=new T[MaxStackSize]; top=-1; } template</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-formula-based-representation/">C++ program to implement Stack 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<constream.h>
template<class T>
class Stack
{
	public:
		Stack(int MaxStackSize);
		~Stack(){delete[] S;}
		int IsEmpty()const{return top==-1;}
		int IsFull()const{return top==MaxTop;}
		T Peek()const;
		void Push(T);
		T Pop();
		void Display();
	private:
		int top; //current top of stack
		int MaxTop; //max val for top
		T *S; //element array
};
	template<class T>
Stack<T>::Stack(int MaxStackSize)
{
	//stack constructor
	MaxTop=MaxStackSize-1;
	S=new T[MaxStackSize];
	top=-1;
}
template<class T>
T Stack<T>::Peek()const
{
	if(IsEmpty()) //top fails
		return 0;
	else
		return S[top];
}
	template<class T>
void Stack<T>::Push(T x)
{
	if(IsFull())
		cout<<"no memory()"; //add fails
	else
	{
		S[++top]=x;
	}
}
	template<class T>
T Stack<T>::Pop()
{
	T x;
	if(IsEmpty())
	{
		cout<<"stack is empty\n";
		return -1;
	}
	else
	{
		x=S[top--];
		return x;
	}
}
	template<class T>
void Stack<T>::Display()
{
	if(IsEmpty())
		cout<<"out of bounds"; //delete fails
	else
		for(int i=top;i>=0;i--)
		{
			cout<<S[i]<<"\t";
		}
}
void menu()
{
	cout<<"1.Push\n 2.Pop\n 3.Peek\n 4.Display\n";
}
void main()
{
	Stack<int>iobj(5);
	int ch,x;
	clrscr();
	do
	{
		menu();
		cout<<"enter the choice\n";
		cin>>ch;
		switch(ch)
		{
			case 1:
				cout<<"enter x value to push into the stack\n";
				cin>>x;
				iobj.Push(x);
				break;
			case 2:
				x=iobj.Pop();
				if(x!=-1)
					cout<<"poped value is \t"<<x<<endl;
				break;
			case 3:
				x=iobj.Peek();
				cout<<"top most value is \t"<<x<<endl;
				break;
			case 4:
				iobj.Display();
				break;
		}
	}while(ch>=1&&ch<=4);
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-formula-based-representation/">C++ program to implement Stack 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-stack-using-formula-based-representation/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to multiply two polynomials maintained as linked lists</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-multiply-two-polynomials-maintained-as-linked-lists/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-multiply-two-polynomials-maintained-as-linked-lists/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Thu, 03 Feb 2011 10:45:58 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[polynomials]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[Linked Lists]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[multiply]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1248</guid>

					<description><![CDATA[<p>#include class poly { private : struct polynode { float coeff ; int exp ; polynode *link ; } *p ; public : poly( ) ; void poly_append ( float c, int e ) ; void display_poly( ) ; void poly_multiply ( poly &#038;p1, poly &#038;p2 ) ; void padd ( float c, int e</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-multiply-two-polynomials-maintained-as-linked-lists/">C++ program to multiply two polynomials maintained as linked lists</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
class poly
{
	private :
		struct polynode
		{
			float coeff ;
			int exp ;
			polynode *link ;
		} *p ;
	public :
		poly( ) ;
		void poly_append ( float c, int e ) ;
		void display_poly( ) ;
		void poly_multiply ( poly &p1, poly &p2 ) ;
		void padd ( float c, int e ) ;
		~poly( ) ;
} ;
poly :: poly( )
{
	p = NULL ;
}
void poly :: poly_append ( float c, int e )
{
	polynode *temp ;
	temp = p ;
	if ( temp == NULL )
	{
		temp = new polynode ;
		p = temp ;
	}
	else
	{
		while ( temp -> link != NULL )
			temp = temp -> link ;
		temp -> link = new polynode ;
		temp = temp -> link ;
	}
	temp -> coeff = c ;
	temp -> exp = e ;
	temp -> link = NULL ;
}
void poly :: display_poly( )
{
	polynode *temp = p ;
	int f = 0 ;
	while ( temp != NULL )
	{
		if ( f != 0 )
		{
			if ( temp -> coeff > 0 )
				cout << " + " ;
			else
				cout << " " ;
		}
		if ( temp -> exp != 0 )
			cout << temp -> coeff << "x^" << temp -> exp ;
		else
			cout << temp -> coeff ;
		temp = temp -> link ;
		f = 1 ;
	}
}
void poly :: poly_multiply ( poly &p1, poly &p2 )
{
	polynode *temp1, *temp2 ;
	float coeff1, exp1 ;
	temp1 = p1.p ;
	temp2 = p2.p ;
	if ( temp1 == NULL && temp2 == NULL )
		return ;
	if ( temp1 == NULL )
		p = p2.p ;
	else
	{
		if ( temp2 == NULL )
			p = temp1 ;
		else		{
			while ( temp1 != NULL )
			{
				while ( temp2 != NULL )
				{
					coeff1 = temp1 -> coeff * temp2 -> coeff ;
					exp1 = temp1 -> exp + temp2 -> exp ;
					temp2 = temp2 -> link ;
					padd ( coeff1, exp1 ) ;
				}
				temp2 = p2.p ;
				temp1 = temp1 -> link ;
			}
		}
	}
}
void poly :: padd ( float c, int e )
{
	polynode *r, *temp ;
	temp = p ;
	if ( temp == NULL || c > temp -> exp )
	{
		r = new polynode ;
		r -> coeff = c ;
		r -> exp = e ;
		if ( p == NULL )
		{
			r -> link = NULL ;
			p = r ;
		}
		else
		{
			r -> link = temp ;
			p = r ;
		}
	}
	else
	{
		while ( temp != NULL )
		{
			if ( temp -> exp == e )
			{
				temp -> coeff += c ;
				return ;
			}
			if ( temp -> exp > c && ( temp -> link -> exp < c ||
						temp -> link == NULL ) )
			{
				r = new polynode ;
				r -> coeff = c;
				r -> exp = e ;
				r -> link = NULL ;
				temp -> link = r ;
				return ;
			}
			temp = temp -> link ;
		}
		r -> link = NULL ;
		temp -> link = r ;
	}
}
poly :: ~poly( )
{
	polynode *q ;
	while ( p != NULL )
	{
		q = p -> link ;
		delete p ;
		p = q ;
	}
}
void main( )
{
	poly p1 ;
	p1.poly_append ( 3, 5 ) ;
	p1.poly_append ( 2, 4 ) ;
	p1.poly_append ( 1, 2 ) ;

	cout << "\nFirst polynomial: " << endl ;
	p1.display_poly( ) ;
	poly p2 ;
	p2.poly_append ( 1, 6 ) ;
	p2.poly_append ( 2, 5 ) ;
	p2.poly_append ( 3, 4 ) ;
	cout << "\nSecond polynomial: " << endl ;
	p2.display_poly( ) ;
	poly p3 ;
	p3.poly_multiply ( p1, p2 ) ;
	cout << "\nResultant polynomial: " << endl ;
	p3.display_poly( ) ;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-multiply-two-polynomials-maintained-as-linked-lists/">C++ program to multiply two polynomials maintained as linked lists</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-multiply-two-polynomials-maintained-as-linked-lists/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to add two polynomials maintained using Linked Lists</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-add-two-polynomials-maintained-using-linked-lists/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-add-two-polynomials-maintained-using-linked-lists/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Thu, 03 Feb 2011 10:29:39 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[Linked Lists]]></category>
		<category><![CDATA[polynomials]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1246</guid>

					<description><![CDATA[<p>#include class poly { private : struct polynode { float coeff ; int exp ; polynode *link ; } *p ; public : poly( ) ; void poly_append ( float c, int e ) ; void display_poly( ) ; void poly_add( poly &#038;l1, poly &#038;l2 ) ; ~poly( ) ; } ; poly :: poly(</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-add-two-polynomials-maintained-using-linked-lists/">C++ program to add two polynomials maintained using Linked Lists</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
class poly
{
	private :
		struct polynode
		{
			float coeff ;
			int exp ;
			polynode *link ;
		} *p ;
	public :
		poly( ) ;
		void poly_append ( float c, int e ) ;
		void display_poly( ) ;
		void poly_add( poly &l1, poly &l2 ) ;
		~poly( ) ;
} ;
poly :: poly( )
{
	p = NULL ;
}
void poly :: poly_append ( float c, int e )
{
	polynode *temp = p ;
	if ( temp == NULL )
	{
		temp = new polynode ;
		p = temp ;
	}
	else
	{
		while ( temp -> link != NULL )
			temp = temp -> link ;
		temp -> link = new polynode ;
		temp = temp -> link ;
	}
	temp -> coeff = c ;
	temp -> exp = e ;
	temp -> link = NULL ;
}
void poly :: display_poly( )
{
	polynode *temp = p ;
	int f = 0 ;

	cout << endl ;
	while ( temp != NULL )
	{
		if ( f != 0 )
		{
			if ( temp -> coeff > 0 )
				cout << " + " ;
			else
				cout << " " ;
		}
		if ( temp -> exp != 0 )
			cout << temp -> coeff << "x^" << temp -> exp ;
		else
			cout << temp -> coeff ;
		temp = temp -> link ;
		f = 1 ;
	}
}
void poly :: poly_add ( poly &l1, poly &l2 )
{
	polynode *z ;
	if ( l1.p == NULL && l2.p == NULL )
		return ;
	polynode *temp1, *temp2 ;
	temp1 = l1.p ;
	temp2 = l2.p ;
	while ( temp1 != NULL && temp2 != NULL )
	{
		if ( p == NULL )
		{
			p = new polynode ;
			z = p ;
		}
		else
		{
			z -> link = new polynode ;
			z = z -> link ;
		}
		if ( temp1 -> exp < temp2 -> exp )
		{
			z -> coeff = temp2 -> coeff ;
			z -> exp = temp2 -> exp ;
			temp2 = temp2 -> link ;
		}
		else
		{
			if ( temp1 -> exp > temp2 -> exp )
			{
				z -> coeff = temp1 -> coeff ;
				z -> exp = temp1 -> exp ;
				temp1 = temp1 -> link ;
			}
			else
			{
				if ( temp1 -> exp == temp2 -> exp )
				{
					z -> coeff = temp1 -> coeff + temp2 -> coeff ;
					z -> exp = temp1 -> exp ;
					temp1 = temp1 -> link ;
					temp2 = temp2 -> link ;
				}
			}
		}
	}
	while ( temp1 != NULL )
	{
		if ( p == NULL )
		{
			p = new polynode ;
			z = p ;
		}
		else
		{
			z -> link = new polynode ;
			z = z -> link ;
		}
		z -> coeff = temp1 -> coeff ;
		z -> exp = temp1 -> exp ;
		temp1 = temp1 -> link ;
	}
	while ( temp2 != NULL )
	{
		if ( p == NULL )
		{
			p = new polynode ;
			z = p ;
		}
		else
		{
			z -> link = new  polynode ;
			z = z -> link ;
		}
		z -> coeff = temp2 -> coeff ;
		z -> exp = temp2 -> exp ;
		temp2 = temp2 -> link ;
	}
	z -> link = NULL ;
}
poly :: ~poly( )
{
	polynode *q ;
	while ( p != NULL )
	{
		q = p -> link ;
		delete p ;
		p = q ;
	}
}
void main( )
{
	poly p1 ;
	p1.poly_append ( 1.4, 5 ) ;
	p1.poly_append ( 1.5, 4 ) ;
	p1.poly_append ( 1.7, 2 ) ;
	p1.poly_append ( 1.8, 1 ) ;
	p1.poly_append ( 1.9, 0 ) ;
	cout << "\nFirst polynomial:" ;
	p1.display_poly( ) ;
	poly p2 ;
	p2.poly_append ( 1.5, 6 ) ;
	p2.poly_append ( 2.5, 5 ) ;
	p2.poly_append ( -3.5, 4 ) ;
	p2.poly_append ( 4.5, 3 ) ;
	p2.poly_append ( 6.5, 1 ) ;
	cout << "\nSecond polynomial:" ;
	p2.display_poly( ) ;
	poly p3 ;
	p3.poly_add ( p1, p2 ) ;
	cout << "\nResultant polynomial: " ;
	p3.display_poly( ) ;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-add-two-polynomials-maintained-using-linked-lists/">C++ program to add two polynomials maintained using Linked Lists</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-add-two-polynomials-maintained-using-linked-lists/feed/</wfw:commentRss>
			<slash:comments>5</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[download]]></category>
		<category><![CDATA[C Programs]]></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[C Programs]]></category>
		<category><![CDATA[download]]></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[linked list]]></category>
		<category><![CDATA[traversal]]></category>
		<category><![CDATA[BST]]></category>
		<category><![CDATA[Binary Search Tree]]></category>
		<category><![CDATA[C Programs]]></category>
		<category><![CDATA[download]]></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>
	</channel>
</rss>
