Alan Curry wrote:
> In article <>,
> Phred Phungus <> wrote:
> |#include <stdio.h>
> |#include <stdlib.h>
> |
> |struct list {
> | struct list *next;
> | int n;
> |};
> |
> |static int *read_numbers(struct list *list)
> [...]
>
> This code, which I posted in another thread, should not be used. It was a
> response to a "challenge" and should be considered mainly as a joke. It does
> technically do everything the challenge requested, while being useless for
> any practical purpose.
>
> In the very same article in which I posted it, I listed 3 reasons why the
> challenge (i.e. make a growable list/array-ish data structure without
> realloc) was stupid. And I also explained the particular shortcoming of my
> code which I was too lazy to fix: it provides no way for the caller to know
> how big the list is.
You mentioned passing a counter to a recursive function.
I didn't see a better posting than yours, and now it's Feb. 9 east of
Chicago.
>
> Yet somehow you missed all of that, and decided to hold on to that code and
> treat it as if it was worthy of further study, and start a new thread
> dedicated to analyzing it. Woosh!
>
I'm having trouble hooking up data structures with a platform and
extensions that are somewhat new to me. So I look for simpler toy
programs that do something similar.
It's not hard to mistake differing forms of lists. I was hoping to do
something with this from Unleashed:
//c11_022.c - naive single linked list, using an array.
#include <stdio.h>
typedef struct ITEM
{
char Title[30];
char Author[30];
int Next;
} ITEM;
int main(void)
{
ITEM List[] =
{
{"UNIX Unleashed", "Burk and Horvath", 2},
{"Algorithms in C", "Sedgewick", 9},
{"Builder Unleashed", "Calvert", 10},
{"C++ Unleashed", "Liberty", 12},
{"Linux Unleashed", "Husain and Parker", 8},
{"Teach Yourself BCB", "Reisdorph", 1},
{"Data Structures & Algorithms", "Lafore", 3},
{"DOS Programmers Reference", "Dettmann & Johnson", 11},
{"C Programming Language", "Kernighan & Ritchie", 6},
{"C++ Programming Language", "Stroustrup", 13},
{"C: How to Program", "Deitel & Deitel", 7},
{"C : A Reference Manual", "Harbison & Steele", 15},
{"The Standard C Library", "Plauger", 5},
{"C Programming FAQs", "Summit", 14},
{"Expert C Programming", "van der Linden", -1},
{"C Unleashed", "Heathfield & Kirby", 4}
};
int Current = 0;
while(Current != -1)
{
printf("Read %s, by %s.\n",
List[Current].Title,
List[Current].Author);
Current = List[Current].Next;
}
return 0;
}
// gcc -D_GNU_SOURCE -Wall -Wextra ll1.c -o out
I think the classification for what is a singly-linked list must be
fairly broad. In this, there aren't new nodes created dynamically.
--
fred