Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > linked list example

Reply
Thread Tools

linked list example

 
 
Barry Schwarz
Guest
Posts: n/a
 
      06-13-2010
On Sun, 13 Jun 2010 14:55:33 -0400, "Bill Cunningham"
<(E-Mail Removed)> wrote:

>Keith Thompson wrote:
>
>> Just in case you aren't already aware of it, Richard was commenting on
>> your tendency to try random things when you run into problems.

>
> Ok I'll try this that's not random. p 143 3 6.6.
>
>for(hashval=0;*s!='\0';s++)


One of your problems is that it is on page 144, not 143. It is
section 6.6 but I have no idea what the " 3" is supposed to
represent.

>
>Why is *s not just s? This speaks of arrays. When I think of linked lists I
>don't think of arrays except arrays of structs. I will work with nlist,
>lookup, and install and try to figure them out. It might work. But do I
>understand what I'm doing? I guess I'll see.


Good to see you take the advice against guessing seriously. And the
answer to your question is obviously no.

--
Remove del for email
 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      06-13-2010
On Sun, 13 Jun 2010 15:32:09 -0400, "Bill Cunningham"
<(E-Mail Removed)> wrote:

>#include <stdio.h>
>#include <string.h>
>
>struct nlist {
> struct nlist *next;
> char *name;
> char *def;
>};
>
>static struct nlist *hashtab[101]; /* What's this? A declared array
>
>to pointer? What's its purpose */


Why are you working from page 144 when you have not yet understood
section 5.12, starting on page 122, where this is particular example
is described and a general procedure is discussed? One more time:-
The chapters in the book build on knowledge discussed in previous
chapters. Do not move on to the next chapter until you understand the
stuff in the current chapter and successfully complete all the
exercises.

>
>unsigned hash(char *s)
>{
> unsigned hashval;
> for (hashval = 0; *s != '\0'; s++) /*Indent gives me an old style
>
>error here */


You have a compiler which is indentation sensitive!?!? Care to tell
us which one?

How many times have you been told to quote the error message? BTW,
what is the difference between an old style error and a new style
error?

>
> hashval = *s + 31 * hasval;


Is there some reason you cannot be bothered to proofread when you copy
code. Did you not get an error message because hasval is an
undeclared variable? Or is this not the code you actually compiled?

> return hashval % 101;
>}
>
> Another attempt.


One has to wonder, attempt at what other than trolling?

--
Remove del for email
 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      06-13-2010
Barry Schwarz a crit :
>
> One has to wonder, attempt at what other than trolling?
>


He is doing that since several YEARS with great success. There will be
always a moron that will answer his "questions"... and there we go.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      06-15-2010
Kenneth Brody <(E-Mail Removed)> writes:

> On 6/11/2010 5:24 PM, Twixer Xev wrote:
>> On 06/11/2010 02:06 PM, Bill Cunningham wrote:
>>> Is this a very simple example of a linked list or is the concept I am
>>> expressing in error again.
>>>
>>> #include "c.h"
>>>
>>> struct cat kat, *p;
>>>
>>> int main(void)
>>> {
>>> for (p = p; p != NULL; p = p->next) {

>>
>> The pointer p was never initialized. What does it point to? Nobody
>> knows.

>
> "p", being declared in global space, was initialized to NULL.
> Therefore, the loop will never be executed.


The definition we can see is no more than a tentative definition. If
no definition with an explicit initialisation is seen by the end of the
translation unit then, yes, p will be initialised to a null pointer, but
p could be initialised in "c.h" to something that is not null without
there being any conflict with what we can see of the program.

--
Ben.
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      06-15-2010
I think I am just going to read kandr2 from chapter 1 to the end. Do the
excercises and if I have any questions about them ask. But I'm still because
of lack of experience as others have; ask questions.

Bill


 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      06-15-2010
"Bill Cunningham" wrote:

> I think I am just going to read kandr2 from chapter 1 to the end. Do
> the excercises and if I have any questions about them ask. But I'm still
> because of lack of experience as others have; ask questions.


I realize you hardly ever, if ever, listen to advise. Nevertheless.

Put K&R away on a shelf so high you need a ladder to get at it. Buy a book
designed for someone with very little programming background. Use that as a
base for your future studies. I have no personal experience with it but the
book by King in the link would be my starting point.

K&R is by far the best book on C ever written, but it assumes a mind set
that you simply do not have. After a few months with your new book,
whatever it is, you can retrieve K&R from the high shelf.

http://www.amazon.com/C-Programming-...6626553&sr=1-1


 
Reply With Quote
 
James Dow Allen
Guest
Posts: n/a
 
      06-16-2010
On Jun 12, 4:47*am, Keith Thompson <(E-Mail Removed)> wrote:
[snip]

Sorry for going off-topic, but I know some c.l.c.'ers
enjoy finding bugs, and I just noticed a "new" one
(albeit unrelated to C language?).

When I examine this thread ("Re: linked list example",
changing to "Starting over...") using GoogleGroup's
"View as Tree" option, I am able to see only the first
ten messages. For the subsequent message clumps, all
that appears where 10 messages should appear is the
trailer: "Create a group etc." The title changes to
"[no subject]"

My guess is that one of the messages in this thread has
a string that looks like HTML, that Google's "clever"(?)
algorithm overlooked it, and that causes these messages
to disappear as though they were inside an HTML tag.
But I am too lazy to determine whether I am competent
enough to confirm or refute this hypothesis.

Using "Standard View" I do see all messages of the thread.

Sorry for going off-topic, but
(a) some c.l.c.'ers *enjoy* solving such puzzles, and
(b) if this does yield a recipe for foiling readers
of Google Groups, I suppose some Usenetters will be
thankful! ...

James Dow Allen

 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      06-16-2010
On 16 June, 08:30, "io_x" <(E-Mail Removed)> wrote:
> "pete" <(E-Mail Removed)> ha scritto nel messaggionews:(E-Mail Removed)...
>
> > Bill Cunningham wrote:
> > void Lf_free(Lf_type *node)
> > {
> > * *Lf_type *next_node;

>
> > * *while (node != NULL) {
> > * * * *next_node = node -> next;
> > * * * *free(node);
> > * * * *node = next_node;
> > * *}
> > }

>
> *void Lf_free(Lf_type *node)
> *{Lf_type *nextNode;
>
> * while(1)
> * * * {if(node==0) *break;
> * * * *nextNode= node->next;
> * * * *free(node);
> * * * *node * *= nextNode;
> * * * }
> *}
>
> why use while(condition){}?
>
> all is easier with while(1){if(conditions) *break;}


void Lf_free(Lf_type *node)
{Lf_type *nextNode;

loop:
if(node==0) goto end_loop;
nextNode= node->next;
free(node);
node = nextNode;
goto loop;
end_loop:
}

why use while() {}?

all is easier with goto loop

or drop the loop

void Lf_free(Lf_type *node)
{
Lf_type *nextNode;
if (node==0) return;
nextNode = node->next;
free(node);
Lf_free (nextNode);
}




 
Reply With Quote
 
Moi
Guest
Posts: n/a
 
      06-16-2010
On Wed, 16 Jun 2010 04:06:13 -0700, Nick Keighley wrote:

> On 16 June, 08:30, "io_x" <(E-Mail Removed)> wrote:
>> "pete" <(E-Mail Removed)> ha scritto nel
>> messaggionews:(E-Mail Removed)...
>>
>> > Bill Cunningham wrote:
>> > void Lf_free(Lf_type *node)
>> > {
>> > * *Lf_type *next_node;

>>
>> > * *while (node != NULL) {
>> > * * * *next_node = node -> next;
>> > * * * *free(node);
>> > * * * *node = next_node;
>> > * *}
>> > }

>>
>> *void Lf_free(Lf_type *node)
>> *{Lf_type *nextNode;
>>
>> * while(1)
>> * * * {if(node==0) *break;
>> * * * *nextNode= node->next;
>> * * * *free(node);
>> * * * *node * *= nextNode;
>> * * * }
>> *}
>>
>> why use while(condition){}?
>>
>> all is easier with while(1){if(conditions) *break;}

>
> void Lf_free(Lf_type *node)
> {Lf_type *nextNode;
>
> loop:
> if(node==0) goto end_loop;
> nextNode= node->next;
> free(node);
> node = nextNode;
> goto loop;
> end_loop:
> }
>
> why use while() {}?
>
> all is easier with goto loop
>
> or drop the loop
>
> void Lf_free(Lf_type *node)
> {
> Lf_type *nextNode;
> if (node==0) return;
> nextNode = node->next;
> free(node);
> Lf_free (nextNode);
> }



I think you forgot one:

void Lf_free(Lf_type *node)
{
if (!node) return;
Lf_free(node->next);
free(node);
}



HTH,
AvK





 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      06-16-2010
On 16 June, 12:31, Moi <(E-Mail Removed)> wrote:
> On Wed, 16 Jun 2010 04:06:13 -0700, Nick Keighley wrote:
> > On 16 June, 08:30, "io_x" <(E-Mail Removed)> wrote:
> >> "pete" <(E-Mail Removed)> ha scritto nel
> >> messaggionews:(E-Mail Removed)...

>
> >> > Bill Cunningham wrote:
> >> > void Lf_free(Lf_type *node)
> >> > {
> >> > * *Lf_type *next_node;

>
> >> > * *while (node != NULL) {
> >> > * * * *next_node = node -> next;
> >> > * * * *free(node);
> >> > * * * *node = next_node;
> >> > * *}
> >> > }

>
> >> *void Lf_free(Lf_type *node)
> >> *{Lf_type *nextNode;

>
> >> * while(1)
> >> * * * {if(node==0) *break;
> >> * * * *nextNode= node->next;
> >> * * * *free(node);
> >> * * * *node * *= nextNode;
> >> * * * }
> >> *}

>
> >> why use while(condition){}?

>
> >> all is easier with while(1){if(conditions) *break;}

>
> > void Lf_free(Lf_type *node)
> > *{Lf_type *nextNode;

>
> > * loop:
> > * * * if(node==0) *goto end_loop;
> > * * * *nextNode= node->next;
> > * * * *free(node);
> > * * * *node * *= nextNode;
> > * * * *goto loop;
> > * end_loop:
> > *}

>
> > why use while() {}?

>
> > all is easier with goto loop

>
> > or drop the loop

>
> > void Lf_free(Lf_type *node)
> > {
> > * * Lf_type *nextNode;
> > * * if (node==0) *return;
> > * * nextNode = node->next;
> > * * free(node);
> > * * Lf_free (nextNode);
> > }

>
> I think you forgot one:
>
> void Lf_free(Lf_type *node)
> {
> * if (!node) return;
> * Lf_free(node->next);
> * free(node);
>
> }
>
>


who's going to explain it to bill...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Airplane Program with Linked Lists. The linked list portion is veryconfusing to me. jawdoc C++ 9 03-10-2008 03:38 AM
Linked list within a linked list joshd C++ 12 10-02-2006 08:57 AM
Linked list, New try (was:Linked list, no out put,help) fool C Programming 14 07-03-2006 12:29 AM
Generating a char* from a linked list of linked lists Chris Ritchey C++ 7 07-10-2003 10:12 PM
Generating a char* from a linked list of linked lists Chris Ritchey C Programming 7 07-10-2003 10:12 PM



Advertisments