Part a)
The main difference between a stack and a queue is how data is inserted and removed from each of them. In a stack, the last element inserted is the first to be removed as compared to a queue where the first element inserted is the first to be removed.
Part b) i)
The enqueue(element) adds an element to the end of the list of elements which represent the queue. If the list of elements is empty, it adds it at the first location or head of the queue.
Part b) ii)
The dequeue(element) removes an element to the front of the list of elements which represent the queue. If the list of elements is empty, no element is removed.
Part c)
//Assumptions: The following state is used
#define MAX_SIZE 100
int stack[MAX_SIZE];
int top = -1;
void push(int *stack, int value) {
if (top >= MAX_SIZE - 1) {
// Stack is full
printf("Stack is full, element was not added!\n");
return;
}
top++;
stack[top] = value;
}
© 2023 Vedesh Kungebeharry. All rights reserved.