Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
Lab Manual It2305

Lab Manual It2305

Ratings: (0)|Views: 79|Likes:
Published by Sathya Arul

More info:

Published by: Sathya Arul on Jul 05, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

10/24/2012

pdf

text

original

 
1.
Develop a Java package with simple Stack and Queue classes. Use JavaDoccomments for documentation
Queue package:
 package queuepackage;public class queue2{private int maxsize;private long[] queArray;private int front;private int rear;private int nitems;public queue2(int s){maxsize=s;queArray=new long[maxsize];front=0;rear=-1;nitems=0;}public void insert(long j){if(rear==maxsize-1)rear=-1;queArray[++rear]=j;nitems++;}public long remove(){long temp=queArray[front++];if(front==maxsize)front=0;nitems--;return temp;}public long peekFront(){return queArray[front];}public boolean isEmpty(){return(nitems==0);}public boolean isFull(){return(nitems==maxsize);
 
}public int size(){return nitems;}}
Stack package:
 package stackpackage;public class stack2{int []a;int top;public stack2(int n){a=new int[n];top=-1;}public void push(int val){if(top==a.length-1){System.out.println("stack overflow");}else{top++;a[top]=val;}}public void pop(){if(top==-1){System.out.println("stack underflow");}else{System.out.println("element popped"+a[top]);top--;}}public void display(){if(top==-1)
 
{System.out.println("stack empty");}else{for(int i=top;i>=0;i--){System.out.println("sstack element :"+a[i]);}}}}
Main program:
 import queuepackage.queue2;import stackpackage.stack2;import java.io.*;public class usestackqueue2{public static void main(String args[]){BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));int c;stack2 s;int n;try{do{System.out.println("1.stack 2.queue");c=Integer.parseInt(sc.readLine());switch(c){case 1:System.out.println("enter the size of stack");n=Integer.parseInt(sc.readLine());s=new stack2(n);int choice;do{System.out.println("1.push,2.pop,3.display,0.exit,enter your choice:");choice=Integer.parseInt(sc.readLine());switch(choice){

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->