I am looking for a multilist tutorial. Does any one know a good multilist tutorial? Thanks in advance.
I am looking for a multilist tutorial. Does any one know a good multilist tutorial? Thanks in advance.
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
What's a multilist? I can think of a few things that I can call a "multilist", so until you nail down the terminology, finding a tutorial is gonna be hard.
Thanks for the reply.
http://cboard.cprogramming.com/showt...ight=multilist
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
I don't see where's the problem with that ... it's like going from a 1D array to a 2D array. Every element in your list doesn't represent a value but rather a pointer to yet another list. How you implement that is up to you really.
Do you have any good example program? I don't have any experience with 2D arrays.
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
Then why are you jumping to a linked version of a 2D array? It's a lot harder to build and work with, and if you don't have experience with 2D arrays, you're going to struggle with the concept of a table as well as the details of linked lists. If you build onto a weak foundation, you'll get a weak structure.I don't have any experience with 2D arrays.
Could you check my work, please? I wanted to create an empty list, is this right?
This is the header stuff:
the function:Code:#ifndef _1_H #define _1_H struct car { int car_km; char *car_color; }; typedef struct node *node_ptr; struct node { char *car_brand; int numberOfcars; struct car cars[100000]; node_ptr next; }; /*Function to create an empty list*/ node_ptr create(void); #endif
Code:#include <stdio.h> #include <stdlib.h> #include "car.h" node_ptr create(void) { node_ptr list=(node_ptr)malloc(sizeof(struct node)); list->car_brand = 0; list->numberOfcars = 0; struct car; list->next = NULL; return list; }, what should I do to fix this? ThanksCode:struct car; ----> car.c:19: warning: ISO C90 forbids mixed declarations and code
Last edited by BoneXXX; 04-20-2007 at 06:38 AM.
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
It means when you declare variables, you have to declare them all at the top of the code block before you start doing things like function calls, value assignments, etc.
Quzah.
Hope is the first step on the road to disappointment.
Okay, I have one more question; did that code create me this node?Thanks
Node
Car Brand
Number of cars which are the same brand
car km,color
Null
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
BoneXXX create yourself a print function which takes a pointer to the list and prints out hte nodes you have created or nothing if it isnt created. ;-)
I don't know how to get int car_km, char *car_color from struct car?
Code:printf("%s", current->car_brand); printf("%d", current->numberOfcars); printf("%d", ?????); /* car km*/ printf("%s", ?????); /* car color*/
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
What are you doing with your node there? You're making a node (I can only assume to make a linked list) which contains an array of 100000 cars? What on earth for?
Quzah.
Hope is the first step on the road to disappointment.
Just for an exercise. it can be 10.
the function:Code:#ifndef _1_H #define _1_H struct car { int car_km; char *car_color; }; typedef struct node *node_ptr; struct node { char *car_brand; int numberOfcars; struct car cars[10]; node_ptr next; }; /*Function to create an empty list*/ node_ptr create(void); #endif
Code:#include <stdio.h> #include <stdlib.h> #include "car.h" node_ptr create(void) { struct car; node_ptr list=(node_ptr)malloc(sizeof(struct node)); list->car_brand = 0; list->numberOfcars = 0; list->next = NULL; return list; } /*Function to print list*/ void print(node_ptr list) { node_ptr current = list->next; printf ("The list is:"); while (current != NULL); { printf("%s", current->car_brand); printf("%d", current->numberOfcars); printf("%d", ?????); /* car km*/ printf("%s", ?????); /* car color*/ } printf("\n"); }
“Example isn't another way to teach, it is the only way to teach” Albert Einstein
You seem to have missed the point. Why is that information its own structure?
Anyway, what part don't you know how to access? Members of an array?Members of a structure?Code:x = array[ y ];An array that's part of a structure?Code:x = foo.x;Members of a structure that are part of another structure?Code:x = foo.bar[ y ];Members of an array of structures that are part of a structure?Code:x = foo.bar.baz;Members of an array that are in a structure, of which you have an array, inside another structure?Code:x = foo.bar[ y ].baz;See how that works? You can go on and on.Code:x = foo.bar[ y ].baz[ z ];
Quzah.
Last edited by quzah; 04-20-2007 at 08:34 PM.
Hope is the first step on the road to disappointment.