Re: Singly Linked List in C



On Fri, 08 May 2009 10:51:05 +0000, James Kuyper wrote:
arnuld wrote:

A queue - see <http://en.wikipedia.org/wiki/Queue_(data_structure)>.
While a linked list is certainly one way to implement a queue, a
circular buffer (see links on that same page) could be a better
approach, if you can accept a fixed upper limit to the number of
elements in the queue. It avoids the space overhead of having each node
contain a pointer to the next element in the queue, and it avoids the
time overhead associated with allocating and deallocating each node.

Well, it can't happen as I have no idea how many elements in the list
will be, that could be 2 or 100 or 9,222.


BTW, even if the upper size is fixed (say 10,000), then if there only 100
elements then it wouldn't it cause the space overhead for extra 9900
elements (in case of circular buffer) ?

Declaring a parameter to be const can make sense for exactly the same
reasons that declaring any other local variable const might make sense.
I would not consider it objectionable, but I would want to make sure
that you understand that making 'sp' const has nothing to do with
protecting the argument of the function from modification.

Now I understand, that 2nd const will be useful only in case I am passing
the address of the original pointer which is not the case here.





--
www.lispmachine.wordpress.com
my email is @ the above blog.


.



Relevant Pages

  • Re: Singly Linked List in C
    ... While a linked list is certainly one way to implement a queue, a circular buffer could be a better approach, if you can accept a fixed upper limit to the number of elements in the queue. ... I would not consider it objectionable, but I would want to make sure that you understand that making 'sp' const has nothing to do with protecting the argument of the function from modification. ... The first const would protect the thing that the pointer points at from change. ...
    (comp.lang.c)
  • Re: Thread safe queue in C
    ... within linux with C and i need a thread safe queue.How can i obtain a ... Anyway, creating a queue with POSIX Threads is rather trivial, I don't see why you can't quickly create one: ... typedef struct queue_s queue; ... queue* const _this, ...
    (comp.programming.threads)
  • Mail in Exchnage 2003 Queue oder Link anzeigen
    ... Ich komme nur einfach nicht an die Mails in der Queue dran. ... Const admin = "administrator" ... Set objWMILocator2 = CreateObject ... For Each m In PendingQueue ...
    (microsoft.public.de.german.scripting.wsh)
  • Re: How to implement a Hash Table in C
    ... code you present for implementing a queue as a circular buffer? ... but generally you want to ration queue length anyway. ... was that the code you present does not implement a bounded queue. ... int queue; ...
    (comp.lang.c)
  • Re: How to implement a Hash Table in C
    ... using void pointers and access functions. ... A circular buffer can be encapsulated in C and still have some ... queue performance. ... Here is my general-purpose heap implementation in C: ...
    (comp.lang.c)