Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
37 views

Name: Pankaj G. Kabra Class: Mca 3 Year

This document discusses stacks, which are abstract data types that store values using three operations: push, pop, and peek. Push adds a new item to the top of the stack. Pop removes the top item from the stack. Peek returns the top item without removing it, and can cause an underflow error if the stack is empty. The document also provides a sample Java implementation of a stack using an ArrayList to store items and support the three stack operations.

Uploaded by

maheshonline99
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Name: Pankaj G. Kabra Class: Mca 3 Year

This document discusses stacks, which are abstract data types that store values using three operations: push, pop, and peek. Push adds a new item to the top of the stack. Pop removes the top item from the stack. Peek returns the top item without removing it, and can cause an underflow error if the stack is empty. The document also provides a sample Java implementation of a stack using an ArrayList to store items and support the three stack operations.

Uploaded by

maheshonline99
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

NAME: PANKAJ G.

KABRA CLASS: MCA 3 RD YEAR

Stack is a abstract datatype By using which we can stores the values But is characterized by only three fundamental operations:

push, pop and stack top. The push operation adds a new item to the top of the stack, or initializes the stack if it is empty. The pop operation removes an item from the top of the stack. The stack top operation gets the data from the top-most position and returns it to the user without deleting it. The same underflow state can also occur in stack top operation if stack is empty.

import java.util.*; public class Stack { private List items; public Stack(int size) { items = new ArrayList(); } public void push(Object item) { items.add(item);

}
public Object pop() { if (items.size() == 0) throw new EmptyStackException(); return items.remove(items.size() - 1); } public boolean isEmpty() { return items.isEmpty(); } }

You might also like