CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2012
    Posts
    6

    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 Attached Files

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Dequeues linked lists

    Quote Originally Posted by toky25 View Post
    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?

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Dequeues linked lists

    Quote Originally Posted by toky25 View Post
    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

  4. #4
    Join Date
    Feb 2012
    Posts
    6

    Re: Dequeues linked lists

    Quote Originally Posted by Paul McKenzie View Post
    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;
    }

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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.

  6. #6
    Join Date
    Feb 2012
    Posts
    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;
    }

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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
  •  





Click Here to Expand Forum to Full Width

Featured