import java.io.*;
public class stack
{
int arr[]=new int[10];
int f,r;
int i,n;
int check;
String str;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
stack()
{
f=-1;
r=-1;
}
public void status() throws Exception
{
System.out.println("\nEnter '1' for Input restricted Dequeue,
'2' for Output restricted Dequeue:");
check=Integer.parseInt(br.readLine());
}
public void push() throws IOException
{
if(r==9)
{
System.out.println("Queue
overflow...");
return;
}
if(check!=1)
{
System.out.println("Specify the location ( Front or
rear):");
str=br.readLine().toLowerCase();
}
else
str="r";
System.out.println("Enter the value to insert: ");
n=Integer.parseInt(br.readLine());
if(f==-1)
{
arr[++f]=n;
r=0;
}
else if(str.charAt(0)=='f')
{
for(i=r+1;i>f;i--)
arr[i]=arr[i-1];
arr[i]=n;
r++;
}
else
{
arr[++r]=n;
}
}
public void display()
{
if(f==-1)
return;
for(i=f;i<=r;i++)
System.out.print("
"+arr[i]);
}
public void pop() throws IOException
{
if(f==-1)
{
System.out.println("Queue
Underflow...");
return;
}
if(check!=2)
{
System.out.println("Specify the location ( Front or
rear):");
str=br.readLine().toLowerCase();
}
else
str="f";
if(f==r)
{
f=-1;
r=-1;
}
else if(str.charAt(0)=='f')
{
f++;
}
else
{
r--;
}
}
public static void main(String args[])throws Exception
{
char op;
BufferedReader br;
stack ob=new stack();
ob.status();
while(true)
{
br=new
BufferedReader(new InputStreamReader(System.in));
System.out.println("\nPress 'p' for push, 'd' for pop and 'q' for
quite:");
op=(char)br.read();
if(op=='p')
ob.push();
else if(op=='d')
ob.pop();
ob.display();
if(op=='q')
break;
br=null;
}
}
}
hello Sir , firstly thank you very much for a great job you are doing .
ReplyDeleteand please I want to ask about simple application on queue as linked list , can you help me ?
any simple one like vowels apps or palindrome please .
Are you looking for this type of program:
ReplyDeleteimport java.io.*;
public class Series
{
char ch[]=new char[100];
BufferedReader br;
String str;
int x=-1,y=-1;
Series()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
public void take()throws Exception
{
System.out.println("Enter the sentence:");
str=br.readLine();
for(int i=0;i<str.length();i++)
{
switch(str.charAt(i))
{
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case 'u':
push(str.charAt(i));
break;
}
}
System.out.println("Elements in the Queue are\n");
pop();
}
private void push(char ch1)
{
ch[++x]=ch1;
if(y==-1)
y=0;
}
private void pop()
{
while(y<=x)
System.out.println(ch[y++]);
}
public static void main(String args[]) throws Exception
{
Series ob=new Series();
ob.take();
System.out.println("Now check the elements in the Queue after the pop operation is completed.\n");
ob.pop();
}
}
Sir can you please tell tell the program for:
ReplyDelete12345
22344
33345
44445
55555
public class Series
ReplyDelete{
int i,j,x=1;
public void show()
{
for(i=0;i<5;i++)
{
x=1;
for(j=0;j<5;j++)
{
if(j<=i)
System.out.print((i+1));
else
System.out.print(x);
x++;
}
System.out.println();
}
}
public static void main(String args[]) throws Exception
{
Series ob=new Series();
ob.show();
}
}
Thank you Sir :-)
ReplyDelete