Stack Reviewer - Data Structure and Algorithm

0.0(0)
studied byStudied by 2 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

18 Terms

1
New cards

Stack

Abstract Data Type (ADT), commonly used in most programming languages.

2
New cards

Linear Data Structure

This structure is following LIFO principle

3
New cards

(LIFO) Last-in-First-out

The elements which is placed (inserted or added) last, is accessed first.

4
New cards

push()

Pushing (storing) an element on the stack

5
New cards

pop()

Removing (accessing) an element from the stack

6
New cards

peek()

This get the top data element of the stack, without removing it

7
New cards

isFull()

Check if stack is full

8
New cards

isEmpty()

check if stack is empty

9
New cards

int peek() {

return stack[top];

}

Algorithm of peek() function

10
New cards

bool isempthy() {

if (top == -1)

return true;

else

return false;

}

Algorithm of isfull() function

11
New cards

bool isfull() {

if (top == MAXSIZE)

return true;

else

return false;

}

12
New cards

Step 1 − Checks if the stack is full.

Step 2 − If the stack is full, produces an error and exit.

Step 3 − If the stack is not full, increments top to point next empty space.

Step 4 − Adds data element to the stack location, where top is pointing.

Step 5 − Returns success

Push Operation

13
New cards

void push (int data) {

if (!isFull()) {

top = top +1;

stack[top] = data;

}eslse {

printf (“Could not insert data, Stack is full.\n”);

}

}

Algorithm for PUSH Operation

14
New cards

 Step 1 − Checks if the stack is empty.

 Step 2 − If the stack is empty, produces an error and exit.

 Step 3 − If the stack is not empty, accesses the data element at which top is pointing.

 Step 4 − Decreases the value of top by 1.

 Step 5 − Returns success.

Pop Operation steps

15
New cards

int pop (int data) {

if (!isempty()){

data = stack [top];

top = top - 1;

return data;

} else {

printf (“Could not retrieve data, Stack is empty.\n”);

}

}

Algorithm for Pop Operation

16
New cards

 Functional call management in recursion

 Undo mechanism in text editors

 Syntax parsing in compilers

 Backtracking algorithms (ex. Solving Mazes)

Application of Stack

17
New cards

Simplicity, Efficiency, Last-in, First-out (LIFO), Limited memory usage

Advantages of Stack Data Structure

18
New cards

Limited Access, Potential for Overflow, Not suitable for random access, Limited Capacity

Disadvantages of Stack Data Structure