Answered step by step
Verified Expert Solution
Question
1 Approved Answer
QUESTION-6) [20 points] Assume that we want to implement two stacks by using only one shared array. Maximum size of the stack array is
QUESTION-6) [20 points] Assume that we want to implement two stacks by using only one shared array. Maximum size of the stack array is N. The top1 and top2 index variables are used to indicate the top elements of the two stacks. Initially top1 will be -1, and top2 will be N, so that both stacks are empty. The top1 starts from index zero and proceeds by incrementing. The top2 starts from index N-1 and proceeds by decrementing. When (top1 +1 == top2), then both stacks are considered as full. top1 1 4 At global scope, define the stack array (integer) with N elements. Also define the top1 and top2 variables and initialize them. 6. 7 Write all of the following C functions whose prototypes are given. 8 top2 void push(int stack_code, int data); Adds the data to the specified stack. (stack_code : 1 means first stack, 2 means second stack). If stack is already full, function displays a warning message. Deletes the top element from the specified stack. If the specified stack is already empty, function displays a warning message. Otherwise, function returns the value of deleted element. int pop(int stack_code); Checks whether the specified stack is empty or not. int is_empty(int stack_code); Function returns TRUE (1), or FALSE (0).
Step by Step Solution
★★★★★
3.45 Rating (148 Votes )
There are 3 Steps involved in it
Step: 1
include int N5 int stackarray5TOP11TOP25 int isfull ifTOP1 1 TOP2 return 1 else return 0 int isempty...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started