Skip to main content

Posts

Showing posts with the label Data & File Structure

Implementation of Binary Tree in C Programming

#include < stdio.h> #include < conio.h> struct node { int data; struct node *right, *left; }*root,*p,*q; struct node *make(int y) { struct node *newnode; newnode=(struct node *)malloc(sizeof(struct node)); newnode->data=y; newnode->right=newnode->left=NULL; return(newnode); } void left(struct node *r,int x) { if(r->left!=NULL) printf("\n Invalid !"); else r->left=make(x); } void right(struct node *r,int x) { if(r->right!=NULL) printf("\n Invalid !"); else r->right=make(x); } void inorder(struct node *r) { if(r!=NULL) { inorder(r->left); printf("\t %d",r->data); inorder(r->right); } } void preorder(struct node *r) { if(r!=NULL) { printf("\t %d",r->data); preorder(r->left); preorder(r->right); } } void postorder(struct node *r) { if(r!=NULL) { postorder(r->left); postorder(r->right); printf("\t %d",r->data); } } void main() ...

Add two polynomial using Doubly Linked list in C Programming

#include #include typedef struct pnode { float coef; int exp; struct pnode *next; }p; p *getnode(); void main() { p *p1,*p2,*p3; p *getpoly(),*add(p*,p*); void display(p*); clrscr(); printf("\n enter first polynomial."); printf("\n-------------------------"); p1=getpoly(); printf("\n-------------------------"); printf("\n enter second polynomial"); p2=getpoly(); printf("\n-------------------------"); printf("\nthe first polynomial is: "); display(p1); printf("\n-------------------------"); printf("\nthe second polynomial is :"); display(p2); printf("\n-------------------------"); p3=add(p1,p2); printf("\naddition of two polynomial is :\n\n"); display(p3); printf("\n-------------------------"); } p *getpoly() { p *temp,*New,*last; int flag,exp; char ans; float coef; temp=NULL; flag=1; printf("\nenter the polynomial in descending order of...

Circular Linked List in C Programming

/*Operations on Circular linked list */ #include #include typedef struct node { int data; struct node *link; }node; node *start=NULL; node *create(node *); node *display(node *); node *insert_beg(node *); node *insert_end(node *); node *insert_before(node *); node *insert_after(node *); node *delete_beg(node *); node *delete_end(node *); node *delete_node(node *); node *delete_after(node *); node *delete_list(node *); void main() { int choice; clrscr(); do { printf("\n1)Create a List.\n2)display\n3)Insert at beg\n4)Insert at end \n5)Insert before given node\n6)Insert after given node\n7)Delete from beg\n8)Delete from end\n9)Delete given node\n10)Delete node after given node\n11)Delete list"); printf("\n12)Quit"); printf("\nEnter your Choice : "); scanf("%d",&choice); switch(choice) { case 1: start=create(start); printf("\n Linked List created."); break; case 2: start = di...

Doubly Linked List in C Programming

/*Operations on Doubly linked list */ #include #include typedef struct node { int data; struct node *next,*prev; }node; node *start=NULL; node *create(node *); node *display(node *); node *insert_beg(node *); node *insert_end(node *); node *insert_before(node *); node *delete_beg(node *); node *delete_end(node *); node *delete_node(node *); node *delete_after(node *); node *delete_list(node *); main() { int choice; clrscr(); do { printf("\n1)Create a List.\n2)display\n3)Insert at beg\n4)Insert at end \n5)Insert before given node\n6)Delete from beg\n7)Delete from end\n8)Delete given node\n9)Delete node after given node\n10)Delete list"); printf("\n11)Quit"); printf("\nEnter your Choice : "); scanf("%d",&choice); switch(choice) { case 1: start=create(start); printf("\n Linked List created."); break; case 2: start = display(start); break; case 3: start = insert_beg(st...

Singly Linked List in C Programming

#include #include #define NULL 0 void main() { struct node{ int data; struct node *link; }; typedef struct node node; int val,ch,ch2,cnt,loc,flag=0,num; node *first=NULL,*temp,*ptr,*prv,*next; char c='y'; clrscr(); while(c=='y') { printf("\n1.Insert \n2.Delete \n3.Display \n4.Search \n5.Exit"); printf("\n Enter your choice:"); scanf("%d",&ch); switch(ch) { case 1: printf("\n1.Insert beginning \n2.Insert End \n3.Insert before given node\n4.insret after given node"); printf("\nEnter your choice:"); scanf("%d",&ch2); printf("\n Enter value:"); scanf("%d",&val); switch(ch2) { case 1: temp=(node*)malloc(sizeof(node)); temp->data=val; if(first==NULL) temp->link=NULL; temp->link=first; first=temp; break; case 2: temp=(node*)malloc(sizeof(node)); temp->data=val; ...

Circular Queue using Array in C Programming

#include #include #define MAX 3 #define NULL -1 void main() { int Q[MAX],i,j,f=NULL,r=NULL,val,ch,item; clrscr(); while(1) { printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit"); printf("\n Enter Your choice:"); scanf("%d",&val); switch(val) { case 1: if((f==0 && r==(MAX-1))||(f==r+1)) printf("\nCircular Queue Overflow."); else { if(r==MAX-1) r=0; else r++; printf("\n Enter value for circular queue:"); scanf("%d",&item); Q[r]=item; if(f==NULL) f=0; } break; case 2: if(f==NULL) printf("\n circular queue is empty."); else { printf("\n Deleted element is :%d",Q[f]); if(f==r) f=r=NULL; else if(f==(MAX-1)) f=0; else f++; } break; case 3: if(f==NULL) printf("\n Circular queue is empty."); else { ...

Implementation of Queue using Linked List in C Programming

#include #include #define NULL 0 void main() { struct node{ int data; struct node *link; }; typedef struct node node; int val,ch; node *front=NULL,*rear=NULL,*temp; char c='y'; clrscr(); while(c=='y') { printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit"); printf("\n Enter your choice:"); scanf("%d",&ch); switch(ch) { case 1: printf("\n Enter value:"); scanf("%d",&val); temp=(node*)malloc(sizeof(node)); temp->data=val; temp->link=NULL; if(front==NULL) front=rear=temp; else rear->link=temp; rear=temp; break; case 2: if(front==NULL) printf("\n Queue is empty."); else { temp=front; printf("\n Deleted element is:%d",temp->data); if(front==rear) front=rear=NULL; else front=front->link; free(temp); } break; case 3: if(front==NULL) printf(...

Implementation of Queue using array in C Programming

#include< stdio.h> #include< conio.h> #define MAX 3 void main() { int Q[MAX],f=-1,r=-1,ch,val,i; char cho='y'; clrscr(); while(cho=='y' || cho=='Y') { printf("\n1.Insert \n2.Delete \n3.Show \n4.Exit "); printf("\n Enter your choice:"); scanf("%d",&ch); switch(ch) { case 1: if(r>=(MAX-1)) { printf("\n Queue overflow"); } else { printf("\n Enter value:"); scanf("%d",&val); r++; Q[r]=val; if(f==-1) { f=f+1; } } break; case 2: if(f==-1) { printf("\n Queue underflow"); } else { val=Q[f]; printf("\n Deleted element is:%d",val); if(f==r) { f=-1; r=-1; } else f++; } break; case 3: if(f==-1) { printf("\n Queue empty"); } else { printf("\n content of queue:\n"...

Stack Using Linked List in C programming

#include #include #define NULL 0 void main() { struct node{ int data; struct node *link; }; typedef struct node node; int val,ch; node *top=NULL,*temp; char c='y'; clrscr(); while(c=='y') { printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit"); printf("\n Enter your choice:"); scanf("%d",&ch); switch(ch) { case 1: printf("\n Enter value:"); scanf("%d",&val); temp=(node*)malloc(sizeof(node)); temp->data=val; if(top==NULL) temp->link=NULL; temp->link=top; top=temp; break; case 2: if(top==NULL) printf("\n Stack is empty."); else { temp=top; printf("\n Deleted element is:%d",temp->data); top=top->link; } break; case 3: if(top==NULL) printf("\n Stack is empty."); else { temp=top; printf("\n Stack content:"); while(temp!=NULL) ...

Stack using Array in C programming

#include #include #define MAX 3 void main() { int S[MAX],i,val,c,top=-1,loc; char ch='y'; clrscr(); while(ch=='y') { printf("\n1.Push \n2.Pop \n3.Peep \n4.Change \n5.Display \n6.Exit"); printf("\n Enter your choice:"); scanf("%d",&c); switch(c) { case 1: if(top>=(MAX-1)) printf("\n Stack Overflow"); else { top++; printf("\n Enter value:"); scanf("%d",&val); S[top]=val; } break; case 2: if(top==-1) { printf("\n Stack underflow"); } else { printf("\n Deleted element is:%d",S[top]); top--; } break; case 3: printf("\n Enter index number:"); scanf("%d",&loc); if((top-loc)+1 OUTPUT 1.Push 2.Pop 3.Peep 4.Change 5.Display 6.Exit Enter your choice:2 Stack underflow 1.Push 2.Pop 3.Peep 4.Change 5.Display 6.Exit Enter your choi...