Вы находитесь на странице: 1из 11

R.

SIVARAMAN

1205174

PROGRAM:
//STACK USING LINKED LIST #include"stdio.h" #include"conio.h" #include"stdlib.h" struct node { float info; struct node *link; }*top=NULL; int c; void push(); void pop(); void disp(); void main() { clrscr(); do{ printf("\n1.PUSH\n"); printf("2.POP\n"); printf("3.DISPLAY\n"); printf("4.EXIT\n"); printf("Enter ur choice:"); scanf("%d",&c); switch(c) { case 1:push();

R.SIVARAMAN

1205174

break; case 2:pop(); break; case 3:disp(); break; case 4:exit(0); default:printf("\nwrong choice"); } }while(c!=4); getch(); } void push() { struct node *temp; float x; temp=(struct node*)malloc(sizeof(struct node)); printf("\nEnter the element to be pushed:"); scanf("%f",&x); temp->info=x; temp->link=top; top=temp; } void pop() { struct node *temp; if(top==NULL) printf("\nSTACK UNDERFLOW\n");

R.SIVARAMAN

1205174

else { temp=top; printf("\nElement popped : %0.2f\n",temp->info); top=top->link; free(temp); } } void disp() { struct node *p; p=top; if(top==NULL) printf("\nSTACK UNDERFLOW\n"); else { printf("Stack elements :\n); while(p!=NULL) { printf("%0.2f\t",p->info); p=p->link; } } }

R.SIVARAMAN

1205174

OUTPUT:
1.PUSH 2.POP 3.DISPLAY 4.EXIT Enter choice:1 Element pushed :5.50 1.PUSH 2.POP 3.DISPLAY 4.EXIT Enter choice:1 Element pushed :6.60 1.PUSH 2.POP 3.DISPLAY 4.EXIT Enter choice:3 Stack elements: 6.60 1.PUSH 2.POP 3.DISPLAY 4.EXIT Enter choice:2 Element popped :6.60 1.PUSH 5.50

R.SIVARAMAN

1205174

2.POP 3.DISPLAY 4.EXIT Enter choice:2 Element popped :5.50 1.PUSH 2.POP 3.DISPLAY 4.EXIT Enter choice:2 STACK UNDERFLOW 1.PUSH 2.POP 3.DISPLAY 4.EXIT Enter choice:4 SREC CBE -22 IT DEPT NOMENCLATURE PREPARATION(5) OUTPUT(5) VIVA(5) RECORD(5) TOTAL(20) SIGN MARKS

R.SIVARAMAN

1205174

PROGRAM: //QUEUE IMPLEMENTATION USING LIST #include"stdio.h" #include"conio.h" #include"stdlib.h" struct node { float info; struct node *link; }*front=NULL,*rear=NULL; int c; void enqueue(); void dequeue(); void disp(); void main() { clrscr(); do{ printf("\n1.ENQUEUE\n 2.DEQUEUE\n 3.DISPLAY-1\n 4.EXIT\n Enter ur choice:"); scanf("%d",&c);

R.SIVARAMAN

1205174

switch(c) { case 1:enqueue(); break; case 2:dequeue(); break; case 3:disp(); break; case 4:exit(0); default:printf("\nwrong choice"); } }while(c!=5); getch(); } void enqueue() { struct node *temp; float x; temp=(struct node*)malloc(sizeof(struct node)); printf("\nEnter the element to be pushed:");

R.SIVARAMAN

1205174

scanf("%f",&x); temp->info=x; temp->link=NULL; if(front==NULL) front=temp; else rear->link=temp; rear=temp; } void dequeue() { struct node *temp; if(front==NULL) printf("\nQUEUE UNDERFLOW\n"); else { temp=front; printf("\nDequeued element: %0.2f\n",temp->info); front=front->link; free(temp);

R.SIVARAMAN

1205174

} } void disp() { struct node *p; p=front; if(front==NULL) printf("\nQUEUE UNDERFLOW\n"); else { printf("Queue elements:"); while(p!=NULL) { printf("%0.2f\t",p->info); p=p->link; } } }

R.SIVARAMAN

1205174

OUTPUT:
1.ENQUEUE 2.DEQUEUE 3.DISPLAY 4.EXIT Enter choice:1 Enqueued element :5.50 1.ENQUEUE 2.DEQUEUE 3.DISPLAY 4.EXIT Enter choice:1 Enqueued element :6.60 1.ENQUEUE 2.DEQUEUE 3.DISPLAY 4.EXIT Enter choice:3 Queue elements: 6.60 1.ENQUEUE 2.DEQUEUE 3.DISPLAY 4.EXIT Enter choice:2 Dequeued element :6.60 1.ENQUEUE 2.DEQUEUE 5.50

R.SIVARAMAN

1205174

3.DISPLAY 4.EXIT Enter choice:2 Dequeued element :5.50 1.ENQUEUE 2.DEQUEUE 3.DISPLAY 4.EXIT Enter choice:2 QUEUE UNDERFLOW 1.ENQUEUE 2.DEQUEUE 3.DISPLAY 4.EXIT Enter choice:4 SREC CBE -22 IT DEPT NOMENCLATURE PREPARATION(5) OUTPUT(5) VIVA(5) RECORD(5) TOTAL(20) SIGN MARKS

Вам также может понравиться