Can anyone tell me how I can create an array of linked lists?
Printable View
Can anyone tell me how I can create an array of linked lists?
Create an array of pointers and let each pointer point to the start of a linked list.
How do I do that ???
:confused:
I don't know, but maybe something like this?
Code:/* For improving code readability */
typedef struct node *list_ptr;
typedef struct node *node_ptr;
/* Also for improving code readability */
typedef enum
{
FIRST_LIST,
SECOND_LIST,
NR_OF_LISTS
} list_index;
/* The basic element of a list */
struct node
{
int some_useful_data;
node_ptr next_node;
};
/* Some lists */
list_ptr list1;
list_ptr list2;
/* An array of lists */
list_ptr array_of_lists [NR_OF_LISTS];
/* Filling the array */
array_of_lists [FIRST_LIST] = list1;
array_of_lists [SECOND_LIST] = list2;
??? You have really lost me....can that be done more easily...that all seems way beyond me :(