March 19th, 2012, 05:06 PM
#1
Dequeues linked lists
This is the output of my program : Initial Queue 40 30
40 was popped from back 30
New Queue 12 10 8 30
i am having problem with the function push_back, i am try push 12 10 8 after 30. in other words the output should be 30 8 10 12
any suggestions
Attached Files
March 19th, 2012, 05:15 PM
#2
Re: Dequeues linked lists
Originally Posted by
toky25
This is the output of my program : Initial Queue 40 30
40 was popped from back 30
You listed 40 before 30 above, so does that mean you are listing the numbers back-to-front?
New Queue 12 10 8 30
i am having problem with the function push_back, i am try push 12 10 8 after 30. in other words the output should be 30 8 10 12
Wait, now it seems like you're saying the opposite. Which is it?
March 19th, 2012, 05:15 PM
#3
Re: Dequeues linked lists
Originally Posted by
toky25
This is the output of my program : Initial Queue 40 30
40 was popped from back 30
New Queue 12 10 8 30
i am having problem with the function push_back, i am try push 12 10 8 after 30. in other words the output should be 30 8 10 12
any suggestions
Did you write the code? If you did, did you debug your code? If you did do that, where in the code does it deviate from what you expect to happen?
Regards,
Paul McKenzie
March 19th, 2012, 05:24 PM
#4
Re: Dequeues linked lists
Originally Posted by
Paul McKenzie
Did you write the code? If you did, did you debug your code? If you did do that, where in the code does it deviate from what you expect to happen?
Regards,
Paul McKenzie
the push_back function pushes the numbers to the front , how can i make it push to the back
void DeQueue :: push_back(int data)
{
ListNode *tmp = new ListNode;
tmp->set_back(storage);
tmp->set_data(data);
storage = tmp;
}
March 19th, 2012, 05:30 PM
#5
Re: Dequeues linked lists
1) Find the last node in the list.
2) Set its next pointer to your new node.
Remember to check the special case of an empty list.
March 19th, 2012, 05:38 PM
#6
Re: Dequeues linked lists
i am not sure if this is right but i dont know have to set the pointer, any hint?
void DeQueue:: push_back(int data)
{
if(front==-1){
storage[0]=data;
front = back = 0;
return;
}
back = (back+1);
storage[back] = data;
}
March 20th, 2012, 08:59 AM
#7
Re: Dequeues linked lists
Okay....the earlier posts made it look like you were using a linked list, but that one looks more like an array. Which is it?
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width