import java.io.*;
class stlin
{
int item;
stlin next;
}
class stack
{
int i=1;
stlin start,curr;
void push(int x)
{
curr=new stlin();
curr.item=x;
curr.next=start;
start=curr;
i++;
}
void pop()
{
if(i==1)
{
System.out.println("Stack is empty");
}
else
{
i--;
curr=start;
System.out.println("Deleted Element is:"+curr.item);
start=start.next;
curr=null;
}
}
void display()
{
if(i==1) System.out.println("no elements");
curr=start;
while(curr!=null)
{
System.out.println(curr.item);
curr=curr.next;
}
System.out.println();
}
}
class stacklin
{
public static void main(String []args) throws IOException
{
stack sl=new stack();
int ch,x;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.println("1.PUSH");
System.out.println("2.POP");
System.out.println("3.SHOW");
System.out.println("4.EXIT");
System.out.println("Enter Ur Choice:");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1: System.out.println("Enter a Number:");
x=Integer.parseInt(br.readLine());
sl.push(x);
break;
case 2: sl.pop();
break;
case 3: sl.display();
break;
case 4: System.exit(0);
}
}
}
}
class stlin
{
int item;
stlin next;
}
class stack
{
int i=1;
stlin start,curr;
void push(int x)
{
curr=new stlin();
curr.item=x;
curr.next=start;
start=curr;
i++;
}
void pop()
{
if(i==1)
{
System.out.println("Stack is empty");
}
else
{
i--;
curr=start;
System.out.println("Deleted Element is:"+curr.item);
start=start.next;
curr=null;
}
}
void display()
{
if(i==1) System.out.println("no elements");
curr=start;
while(curr!=null)
{
System.out.println(curr.item);
curr=curr.next;
}
System.out.println();
}
}
class stacklin
{
public static void main(String []args) throws IOException
{
stack sl=new stack();
int ch,x;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.println("1.PUSH");
System.out.println("2.POP");
System.out.println("3.SHOW");
System.out.println("4.EXIT");
System.out.println("Enter Ur Choice:");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1: System.out.println("Enter a Number:");
x=Integer.parseInt(br.readLine());
sl.push(x);
break;
case 2: sl.pop();
break;
case 3: sl.display();
break;
case 4: System.exit(0);
}
}
}
}
No comments:
Post a Comment