Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ike Naar <ike@iceland.freeshell.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: dequeue() not working |
| Date | 2012-06-21 08:37 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrn3vfsju5nah.m6r.ike@iceland.freeshell.org> (permalink) |
| References | <4fe2c91e$0$289$14726298@news.sunsite.dk> |
On 2012-06-21, arnuld <sunrise@invalid.address> wrote:
> struct myQ* dequeue(struct myList** s)
> {
> struct myQ *temp, *prev;
> if(NULL == s || NULL == *s) return 0;
> if(NULL == (*s)->head) return 0;
> prev = (*s)->head;
> temp = (*s)->head;
> if(NULL == (*s)->head->next)
> {
> struct myQ* retp = (*s)->head;
> (*s)->head = (*s)->tail = NULL;
> return retp;
> }
>
> while(temp->next)
> {
> prev = temp;
> temp = temp->next;
> }
>
> (*s)->tail = prev;
Didn't you forget to set prev->next to NULL here?
>
> return temp;
> }
The code above could be simplified in a couple of ways.
First, you can change the type of s to struct mylist*
and replace every (*s) by s.
(and of course, change the call dequeue(&s) to dequeue(s)).
Second, the tail pointer in a struct MyList does not add
much value, so you might as well get rid of it. The last
element in a list is already characterized by element->next
being NULL, and it is that property that you use everywhere.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
dequeue() not working arnuld <sunrise@invalid.address> - 2012-06-21 07:11 +0000
Re: dequeue() not working Ike Naar <ike@iceland.freeshell.org> - 2012-06-21 08:37 +0000
Re: dequeue() not working Ike Naar <ike@iceland.freeshell.org> - 2012-06-21 08:42 +0000
Re: dequeue() not working Ike Naar <ike@iceland.freeshell.org> - 2012-06-21 08:43 +0000
Re: dequeue() not working Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-06-21 11:09 +0200
Re: dequeue() not working jgk@panix.com (Joe keane) - 2012-06-22 23:23 +0000
Re: dequeue() not working Martin Shobe <martin.shobe@yahoo.com> - 2012-06-23 00:09 +0000
Re: dequeue() not working Heikki Kallasjoki <fis+usenet@zem.fi> - 2012-06-23 00:10 +0000
What's in a name? Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-06-23 12:19 +0200
Re: dequeue() not working Neil Cerutti <neilc@norwich.edu> - 2012-06-21 12:38 +0000
Re: dequeue() not working pete <pfiland@mindspring.com> - 2012-06-23 00:39 -0400
csiph-web