If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > help help i need help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-13-05, 14:10
hashmania hashmania is offline
Registered User
 
Join Date: Dec 2005
Posts: 2
Question help help i need help

i need this problem 2 be solved quickly plz help me i hve a simple code that i wrote i hope it code helps u

a double-ended queue or deque(pronounced"deck")is a generalization of botha stackand a queue.
itsupports the insertion and removal of items from either the front of the back of the queue.
using a dynamiclist,implement a deque class that supportsthe following:
deque //construct an empty deque.
bool is Empty //return true if the queue is empty,false otherwise.
void addfirst(Item item) //insert an item @ the front of the qeueu.
void addlast(Item item) //insert the item @ the end of the qeueu.
Item removerfirst() //delete and return the first item in the queue.
Item removelast() //delete and return the last item in the queue
And plz write the main() for me

# include <iostream.h>

class deque
{
private:
struct node
{
int data ;
node * next;
};
node* head;
node* tail;
public:
deque();
bool empty ();
void enque(int e);
void addfirst(int item);
void addlast(int item);
int removefirst(int e);
int removelast(int e);
};

deque::deque()
{
head=0;
tail=0;

}

bool deque ::empty()
{
return(head==0);
}

void deque::enque(int e)
{
node*p=new node;
p->data=e;
p->next=0;
if(head==0)
{
head=p;
}
else
{
tail->next=p;
}
tail=p;
}

void deque::addfirst(int item)
{
node*p=new node;
p->data=item;
p->next=head;
}
void deque::addlast(int item)
{
node*p=new node;
p->data=item;
tail->next=p;
tail=p;
}

int deque::removefirst(int e)
{
node*z=new node;
e=z->data;
head=head->next;
delete z;
return e;
}

int removelast(int e)
{
node* z=new node;
node* w=new node;
while(z->next!=tail)
{
z=z->next;
w=tail;
e=w->data;
tail=z;

}
delete w;
return e;
}







a double-ended queue or deque(pronounced"deck")is a generalization of botha stackand a queue.
itsupports the insertion and removal of items from either the front of the back of the queue.
using a dynamiclist,implement a deque class that supportsthe following:
deque //construct an empty deque.
bool is Empty //return true if the queue is empty,false otherwise.
void addfirst(Item item) //insert an item @ the front of the qeueu.
void addlast(Item item) //insert the item @ the end of the qeueu.
Item removerfirst() //delete and return the first item in the queue.
Item removelast() //delete and return the last item in the queue
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On