Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

John plans to add a new operation Peek to the stackADT. This new operation returns the top element of the stack, but, unlike Pop, the

image text in transcribed

John plans to add a new operation Peek to the stackADT. This new operation returns the top element of the stack, but, unlike Pop, the stack is unchanged. The new version of stack.h now looks like the follows. / * File: stack.h */ typedef struct stackCDT *stackADT; typedef int stackElementT; stackADT EmptyStack(void); void Push(stackADT, stackElementT); stackElementT Pop(stackADT); stackElementT Peek(stackADT); / This is new. / int StackDepth(stackADT); int StackIsEmpty(stackADT); John has a new idea of using linked lists to implement the stackADT in the file stack.c. The main ideas are illustrated in the Figure 1. Note: - The type stackADT is, as usual, a pointer to struct stackCDT. typedef struct stackCDT *stackADT; - The structure struct stackCDT contains only one variable named topOfStack, which is a pointer to a structure cellT. If the stack is empty, then topOfStack should be NULL. struct stackCDT { cellT *topOfStack; } - The structure cellT contains two variables: one stackElementT variable named value that stores a stack element, and one pointer named next, which points to the cellT that stores the element below it, or NULL if there is no next element. typedef struct cellT \{ stackElementT value; struct cellT *next; } cellT; John has implemented the Peek operation in stack.c, as follows. stackElementT Peek(stackADT stack) \{ if (StackIsEmpty(stack)) exit(EXIT_FAILURE); \} return stack->topOfStack->value; Implement other parts of the file stack.c using the above ideas

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions