[go: up one dir, main page]

0% found this document useful (0 votes)
18 views1 page

Peek, Isempty, Isfull in Stacks and Queues

The document explains the functions peek, isEmpty, and isFull used in stacks and queues. Peek allows inspection of the top element of the stack, isEmpty checks if the structure has elements, and isFull determines if a fixed-size stack has reached its capacity. It also includes a task to implement these functions with specific return values based on the stack's state.

Uploaded by

Asif Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Peek, Isempty, Isfull in Stacks and Queues

The document explains the functions peek, isEmpty, and isFull used in stacks and queues. Peek allows inspection of the top element of the stack, isEmpty checks if the structure has elements, and isFull determines if a fixed-size stack has reached its capacity. It also includes a task to implement these functions with specific return values based on the stack's state.

Uploaded by

Asif Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1/26/25, 4:12 PM Peek, isEmpty, isFull in Stacks and Queues

Peek, isEmpty, isFull


The peek , isEmpty , and isFull are some other functions used in stacks.

1. peek - This function allows you to look at the element at the top of the
stack. It's a way to inspect the next item that would be removed if a pop
operation were to be performed.

For a stack: Peek would return the last item added (since stacks follow
Last In, First Out order).

2. isEmpty - This function checks whether a data structure (like a stack,


queue, list, etc.) contains any elements or not.

If the data structure contains no elements, isEmpty returns true.


If there is at least one element in the data structure, isEmpty returns
false.

3. isFull - This function is typically relevant for a fixed size stack. It allows you
to determine if the data structure has reached its maximum capacity.

Task
You are given implementation of peek,isEmpty and isFull function of stack
Peek function return the element present in the peek of stack in case stack
is empty it returns -1.
isFull fuction return 1 if the stack is full and return 0, if the stack is not full.
Fill the dash present in the function and submit the code.

https://www.codechef.com/learn/course/stacks-and-queues/LSTACKS/problems/STACK12 1/1

You might also like