Posts

Conversion of Infix to Postfix Notation lab program

 #include<stdio.h> #include<ctype.h> char stack[20]; int top = -1; void push(char); char pop(); int precedence(char); int main() { char infix[20],postfix[20]; int i,j=0; printf("Enter an Infix expression:-\t"); gets(infix); for (i = 0 ; infix[i] != '\0' ; i++) { if(isalnum(infix[i])) { postfix[j] = infix[i]; j++; } else if(infix[i] == '(') push(infix[i]); else if(infix[i] == ')') { while(stack[top] != '(') { postfix[j] = pop(); j++; } pop(); } else { while((top != -1 && stack[top] != '(') && (precedence(stack[top]) >= precedence(infix[i]))) { postfix[j] = pop(); j++; } push(infix[i]); } } while(top != -1) { postfix[j] = pop(); j++; } postfix[j] = '\0'; printf("PostFix Expression = %s\n",postfix); return 0; } void push(char c) { top++; stack[top] = c; } char pop...

Implementation of Stack operations using Linked List lab program

 #include<stdio.h> #include<stdlib.h> struct node { int data; struct node *link; }*top = NULL; void push(); void pop(); void peek(); void display(); int main() { int n; printf("Stack Menu:-\n\n1.Push\n2.Pop\n3.Peek\n4.Display\n5.Exit\n\n"); while(1) { printf("Enter your choice\t"); scanf("%d",&n); switch(n) { case 1: push(); break; case 2: pop(); break; case 3: peek(); break; case 4: display(); break; case 5: exit(1); default: printf("Please enter a valid choice\n"); }; } return 0; } void push() { int n; struct node *temp; temp = (struct node *)malloc(sizeof(struct node)); printf("Enter value\t"); scanf("%d",&n); temp->data = n; temp->link = NULL; if(top == NULL) top = temp; else { temp->link = top; top = temp; } } void pop() { if(top == NULL) printf("Underflow - No elements to delete\n"); else ...

Implementation of stacks using Arrays lab program

#include<stdio.h> #include<stdlib.h> void push(); void pop(); void peek(); void display(); # define size 5 int arr[size]; int top = -1; int main() { int n; printf("Stack Menu:-\n\n1.Push\n2.Pop\n3.Peek\n4.Display\n5.Exit\n\n"); while(1) { printf("Enter your choice\t"); scanf("%d",&n); switch(n) { case 1: push(); break; case 2: pop(); break; case 3: peek(); break; case 4: display(); break; case 5: exit(1); default: printf("Please enter a valid choice\n"); }; } return 0; } void push() { if(top == size-1) printf("Overflow Occured\n"); else { int n; printf("Enter value\t"); scanf("%d",&n); top++; arr[top] = n; } } void pop() { if(top == -1) printf("Underflow Occured\n"); else { printf("Element %d is deleted\n",arr[top]); top--; } } void peek() { if(top == -1) printf("Stack is E...

Unit-2 chapter-1 STACKS AND ITS APPLICTIONS

                                                  UNIT-2                                     STACKS and QUEUES     Unit-II: Stacks and Queues Stacks: The Stack: Definition, operations, implementation using arrays, linked list and Stack applications: Infix to postfix expression conversion, Evaluation of Postfix expressions, balancing the symbols. Queue: definition, operations, implementation using arrays, linked list&it’sApplications. Circular queue : Definition &its operations, implementation, Dequeue : definition ...