Thread: Linked List Queue

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    13

    Linked List Queue

    for my assignment, i had to simulate a taxi rank that is implemented as a queue via an array that can hold up to a maximum of six taxis., which i completed but now its telling me to implement it in a linked list queue, im not sure how to start this. any help will be welcome.

  2. #2
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    Start here Linked Lists in C Tutorial - Cprogramming.com

    The logic isn't any different. It's still FIFO. It still uses pointers to front and rear. Now you implement with dynamic nodes of data and have to solve maintaining the maximum queue size differently.

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by Tclausex View Post
    Another source for someone to really understand linked lists can be found here.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by std10093 View Post
    Another source for someone to really understand linked lists can be found here.
    Can't say I like that unnecessary pointer typedef.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I see what you saying. Salem had also pointed out a bad effect of typedef in similar situations, but as I have written in the link "This code comes from the course of ip, from DIT, Athens.", so I feel a bit uncomfortable to modify it.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  6. #6
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Quote Originally Posted by std10093 View Post
    Another source for someone to really understand linked lists can be found here.
    to really understand?

    The code may be all and good. But for someone looking to have the concept explained to them with more than lines of source (confusing at that) code, not a great resource.

    Linked List Basics

    The link provides a pdf document that covers linked lists to exhaustion, along with some sample problems.
    Last edited by jwroblewski44; 03-28-2013 at 03:20 PM.

  7. #7
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Do you really read it? It has very good comments in my mind. Reading good and commented code is always helpful. I did not say that the link is the only source of course. But theory only is not enough. This was what made me understand them when on ip and that's why I forward it to others.-
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  8. #8
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    >Do you really read it?
    Well, I tried. But the formatting is 'not great'. And to have a comment on every single line is not what you want. In fact, it takes away from the code by distracting the reader.

  9. #9
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    It has very good comments in my mind. Reading good and commented code is always helpful.
    I agree completely.

    That said, the interface itself is pretty decent from what I saw, and I perfectly well understand the comments documenting the intended state of the list. Those comments are great for this, but the sort of thing here is not what we want newbies emulating.

    Code:
    if (n_th(alist, 2, &v))                     /* Return 2nd element */
    That sort of thing is awful. If `n_th' is documented properly, the comment is redundant in the worst way. If someone comes along and changes that to get the third element without updating the comment we have "out of sync" documentation. It is annoying to work with in small doses; in complex projects it can be a significant problem.

    Again, I know this tutorial, but we don't want newbies learning that kind of commenting.

    Soma

  10. #10
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Indeed. I did not mean to say that the code was not an accurate representation of a linked list. Just not "noob-friendly".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. standard linked list or Queue in C??
    By dayalsoap in forum C Programming
    Replies: 1
    Last Post: 06-13-2011, 02:12 PM
  2. Is a queue essentially a linked-list?
    By dudeomanodude in forum C++ Programming
    Replies: 4
    Last Post: 03-17-2008, 07:54 AM
  3. linked-list queue
    By the_winky_files in forum C Programming
    Replies: 17
    Last Post: 11-21-2005, 03:57 PM
  4. Linked List Queue Implementation help
    By Kenogu Labz in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2005, 10:14 AM
  5. Linked List implementation of Queue
    By tdm2792 in forum C Programming
    Replies: 5
    Last Post: 11-04-2001, 04:04 PM