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

Program Part2 Assignment 6

Uploaded by

ranjansatya6371
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)
3 views2 pages

Program Part2 Assignment 6

Uploaded by

ranjansatya6371
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

import [Link].

Scanner;

class Node
{
int info;
Node next;
}

public class Check5


{
// Push Operation
public static Node push(Node top)
{
Scanner sc = new Scanner([Link]);

Node newNode = new Node();

[Link]("Enter Element:");
[Link] = [Link]();

// Insert at beginning
[Link] = top;

top = newNode;

[Link]("Element Pushed");

return top;
}

// Pop Operation
public static Node pop(Node top)
{
if(top == null)
{
[Link]("Stack Underflow");
return top;
}

[Link]("Deleted Element is: " + [Link]);

top = [Link];

return top;
}

// Display Operation
public static void display(Node top)
{
if(top == null)
{
[Link]("Stack is Empty");
return;
}

Node temp = top;

[Link]("Stack Elements:");
while(temp != null)
{
[Link]([Link]);
temp = [Link];
}
}

// Main Method
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);

Node top;
top = null;

while(true)
{
[Link]("\n**** MENU ****");
[Link]("0: Exit");
[Link]("1: Push");
[Link]("2: Pop");
[Link]("3: Display");

[Link]("Enter your choice:");


int choice = [Link]();

switch(choice)
{
case 0:
[Link](0);

case 1:
top = push(top);
break;

case 2:
top = pop(top);
break;

case 3:
display(top);
break;

default:
[Link]("Wrong Choice");
}
}
}
}

You might also like