Given a sequence of push and pop operations and an integer representing the size
ID: 3638467 • Letter: G
Question
Given a sequence of push and pop operations and an integer representing the size of anarray in which a stack is to be implemented, design an algorithm to determine whether or not overflow occurs. The algorithm should not use a stack. Implement the algorithm as a C program.
Explanation / Answer
Hi, my friend here is the program u want if u need more help message me PLEASE RATE #include #include #include struct node { int data; struct node *link; }; struct node *top=NULL,*temp; void main() { int choice,data; while(1)//infinite loop is used to insert/delete infinite number of nodes { printf(" 1.Push 2.Pop 3.Display 4.Exit "); printf(" Enter ur choice:"); scanf("%d",&choice); switch(choice) { case 1: temp=(struct node *)malloc(sizeof(struct node)); printf("Enter a node data :"); scanf("%d",&data); temp->data=data; temp->link=top; top=temp; break; case 2: if(top!=NULL) { printf("The poped element is %d",top->data); top=top->link; } else { printf(" Stack Underflow"); } break; case 3: temp=top; if(temp==NULL) { printf(" Stack is empty "); } while(temp!=NULL) { printf("->%d->",temp->data); temp=temp->link; } break; case 4: exit(0); } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.