diptojit Active member
| Subject: Re: algorithms in simple data structures..?? Fri Mar 19, 2010 12:24 am | |
| don't know.....this is the program from the sample paper....I don't think the sample question is exactly on a deque.... |
|
diptojit Active member
| Subject: Re: algorithms in simple data structures..?? Fri Mar 19, 2010 12:26 am | |
| anyways... i checked it out and it's working fine now.....I created a main method to check it....have a look...
here's the newer version of the program....along with the main method
import java.io.*; class chain { int ele[]; int cap,front,rear; chain(int max) { cap=max; front=0;rear=0; ele=new int[cap]; } void pushfront(int v) { if(front>0) { ele[front-1]=v; front--; } else if(front==0&&rear==0) { ele[0]=v;} else { System.out.println("Full from front"); } } int popfront() { if(front==0&&rear==0) { return 999; } else { front=front+1; return(ele[front-1]); } } void pushrear(int v) { if(rear==cap-1) { System.out.println("Full from rear"); } else { ele[rear+1]=v; rear++; } } int poprear() { if(front==0&&rear==0) { return 999;} else { rear=rear-1; return(ele[rear+1]); } } void display() { int i; for(i=front;i<=rear;i++) { if(ele[i]!=0) { System.out.print(ele[i]+" "); } } } } test class :- import java.io.*; class test { void main()throws IOException { chain obj=new chain(10); obj.pushfront(5); obj.pushrear(; obj.pushrear(13); obj.display(); System.out.println(); obj.popfront(); obj.display(); System.out.println(); obj.pushrear(1); obj.display(); System.out.println(); obj.poprear(); obj.display(); System.out.println(); } } |
|
G-7 Active member
| Subject: Re: algorithms in simple data structures..?? Fri Mar 19, 2010 12:27 am | |
| yea..there is no application for deque for us to study... jus the theory... jus superficial...! but i like to do it cuz itz challenging... maybe we can do a code during the holidays.! |
|
G-7 Active member
| Subject: Re: algorithms in simple data structures..?? Fri Mar 19, 2010 12:30 am | |
| nay.. a small bug still there...try poppin from the front...after pushing front...! |
|
G-7 Active member
| Subject: Re: algorithms in simple data structures..?? Fri Mar 19, 2010 12:42 am | |
| All the best everyone....may God help u and also me..
I'll pray thay every one of us can get good marks and w can do the xam very well..!!
G0od night everyone..!
ALL IZZ WELL...!!! |
|
Sponsored content
| Subject: Re: algorithms in simple data structures..?? | |
|
|
|