0% found this document useful (0 votes)
12 views2 pages

Java Array Stack Implementation

The document contains code for implementing a stack data structure using an array. It defines methods for pushing elements onto the stack, accessing the top element, popping elements off the stack, and displaying the contents of the stack. The main method demonstrates using the stack by pushing multiple elements, checking the top element, and displaying the contents.

Uploaded by

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

Java Array Stack Implementation

The document contains code for implementing a stack data structure using an array. It defines methods for pushing elements onto the stack, accessing the top element, popping elements off the stack, and displaying the contents of the stack. The main method demonstrates using the stack by pushing multiple elements, checking the top element, and displaying the contents.

Uploaded by

yayanariff96
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Stack Using Array… Complete the missing code

public class Stack {

//required variable -> define here

public void push(int num)


{
//push code -> define here
}

public int top()


{
// top code -> define here
}

public void pop()


{
stackTop--;
number[stackTop] = 0;
}

public void display()


{
for (int temp = stackTop - 1; temp >= 0; temp--)
{
[Link](number[temp]+",");
}
}

public static void main(String [] args)


{
Stack intStack = new Stack();
[Link](10);
[Link]("Top Element: "+ [Link]());

//[Link]();
[Link](20);
[Link](30);
[Link](40);
[Link](50);
[Link](60);
//[Link]([Link]());

[Link]();
[Link]();
[Link]("Top Element: "+ [Link]());
}

You might also like