0% found this document useful (0 votes)
14 views3 pages

Copy Stack

STACK EXAMPLE
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)
14 views3 pages

Copy Stack

STACK EXAMPLE
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

import [Link].

Scanner;

class copyStack{

int stackArray[], top, maxsize;

public copyStack(int size){

maxsize = size;

stackArray = new int[size];

top = -1;

public boolean isFull(){

return top == maxsize - 1;

public boolean isEmpty(){

return top == -1;

public void push(int num){

if (isFull())

[Link]("The stack is full no more elements can be added");

else

stackArray[++top] = num;

public int pop(){

int temp = 0;

if (isEmpty())

[Link]("The stack is empty no elements to remove");

else{

temp = stackArray[top];

top--;

}
return temp;

public void displayStack(){

for(int i = 0; i <= top; i++){

[Link](stackArray[i] + "\t");

[Link]();

public static void main(String args[]){

copyStack s1 = new copyStack(5);

copyStack temp = new copyStack(5);

copyStack s2 = new copyStack(5);

[Link](10);

[Link](15);

[Link](9);

[Link](4);

[Link](1);

[Link](190);

[Link]("The elements of stack 1:\n");

[Link]();

[Link]([Link]());

[Link]([Link]());

[Link]([Link]());

[Link]([Link]());

[Link]([Link]());

[Link]("\nThe elements of stack temp:\n");

[Link]();
[Link]([Link]());

[Link]([Link]());

[Link]([Link]());

[Link]([Link]());

[Link]([Link]());

[Link]("\nThe elements of stack 2:\n");

[Link]();

You might also like