Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
Question
Book Icon
Chapter 20.3, Problem 20.5CP
Program Plan Intro

Stack:

  • A stack is a linear data structure.
  • The stack follows the order LIFO (last-in-first-out) for performing operations.
  • The two main operations performed on stack are,
    • Push() – Add item to stack.
    • Pop() – Remove item from stack.

“Push()” method:

The “Push()” is a method used to insert or add an item to the stack. The element is pushed at the top of the stack.

  • The “Push()” will have an item as its argument and it returns the argument which is passed.
  • If the stack is full and when “push()” method is calls the push will generate “StackOverFlowException” and return.

Syntax for push operation:

STACK.push(E element)

“Pop()” method:

  • The method “pop()” is used to delete an item from the stack.
  • This method does not have any argument and when this method called on a stack, the element at the top of the stack is removed.
  • This method will return the top element before removing it.
  • If the stack is empty (its size is equal to 0) and when the “pop()” method is called pop throws the “EmptyStackException” object.

Syntax for pop operation:

  STACK.pop()

Blurred answer
Students have asked these similar questions
I need help to solve the following case, thank you
hi I would like to get help to resolve the following case
Could you help me to know  features of the following concepts: - defragmenting. - dynamic disk. - hardware RAID
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT