Thread: Help with FIFO QUEUE

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    in your QueuItem constructor
    pData = mData; - this should be opposite

    Code:
    delete mpHead;
    mpHead = mpHead->getNext();
    you cannot access deleted pointer

    your const correctness went out of window

    your printList changes the head pointer making it impossible to remove head or print list once again
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    72
    Quote Originally Posted by vart View Post
    in your QueuItem constructor
    pData = mData; - this should be opposite

    Code:
    delete mpHead;
    mpHead = mpHead->getNext();
    you cannot access deleted pointer

    your const correctness went out of window

    your printList changes the head pointer making it impossible to remove head or print list once again
    I changed the Queueitem constructor to:
    Code:
    QueueItem::QueueItem (char *pData, int id)
    {
    strncpy(mData, pData);
    mNodeID = id;
    mpNext = NULL;
    }
    for the removeItem function, after deleting the head shouldn't i push the next item on top??
    How does the printlist change the head pointer?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  2. Need help with FIFO Queue using Singly Linked Lists
    By astou in forum C++ Programming
    Replies: 6
    Last Post: 03-15-2008, 02:36 PM
  3. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 09:09 PM
  4. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 11:39 AM
  5. queue help
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-29-2001, 09:38 AM