• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

list of lists help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

shortyes

Member
Joined
Oct 2, 2002
Location
Tampa, FL
Hey all, can someone help me with the list of lists? Where can I get more information about this?

My teacher was not very detailed and I have to write it and so far I am stuck on the structure. Not sure where to begin. My text doesn't offer much help?

Anyone know of a book or url that explais it in more detail?
 
Your still going to have to give us a bit more. Linked lists? Double linked lists? Arrays?

Where are you having problems? Could you post the code you have so we can help you debug it? Could you post what you are supposed to be doing?
 
the problem is I do not know where to start, I am just looking for some information of list of lists.
 
'list of lists' really isnt very descriptive.
what do you need to do with this 'list of lists' exactly? i think that would be a good thing to figure out for starters, then we can actually help you.
 
Sorry I thought List of Lists was a common programming method later on.

Think of linked list or queues. aka 1----> 3---> 5---> 23 and so forth

assume there is a Queue *p

in box 0 there is the value 1 if I were to do p->next the value I get is 3

and for forth

This I understand what I do not understand is how to make the row 1 3 5 23 ....into the main row and have another linked list attached to each of the numbers like

in the column 1 there will be 1-->45--->56 but 1 is still attached to 1--->3---->5

I'm not sure if I explained to well since I am a little confused myself
 
So, it sounds like you want a linked list of linked lists. For each row you will need a linked list that contains the numbers. Then you will have to have a rows list. Each node (box?) will contain a pointer to the first node of one of the rows list. Note that you will have two different types of nodes, one contains an element and the other contains a pointer to a row of elements. Let me see if I can draw it.

PHP:
first
  |
  V
row0 -> node00 -> node01 -> node02 ->
  |              |                 |               |
  |           val00         val01        val02
  |
  V
row1 -> node10 -> node11 -> node12 ->
  |              |                 |               |
  |           val10         val11        val12
  |
  V
row2 -> node20 -> node21 -> node22 ->
  |              |                 |               |
  |           val20         val21        val22
  |
  V
 
yes that is what I need. The question I have is where can I find out how to make something like that? My text does not have anything like that.

and google is no help
 
Each of your nodes could to have two pointers. One points to the next node in the list, and the other points to the head of another list. Does that make any sense? Are you using classes (the object oriented kinds. ie: a list class) for this?
 
Cowboy Shane said:
Each of your nodes could to have two pointers. One points to the next node in the list, and the other points to the head of another list. Does that make any sense? Are you using classes (the object oriented kinds. ie: a list class) for this?

Not really sorry. This is my 2nd semester of C programming and the teacher basically toss us into the fire.

I know how to use linked list but never actually made it. The teachers always gave us the xxxx.h file and made us write the xxx.c

This time he wants us to write both the .h and the .c and I have no idea how to write the .h
 
Not really. Hashing is more complicated than what you need. Instead you should be looking for linked lists.

Are you using C or C++? It makes a big difference in this case since it is easier in C++. I'll assume you mean C.

In the .h file you want to make your structure definitions as well as function prototypes. The idea is to have the minimum amount of stuff in the .h file while still completly specifying how to use the .c file it will be associated with. This way, when another .c file wants to use the functions in the first .c file it can include the .h file and the compilier will have everything it needs.

For the list of lists, you will need at least two structures. One will be an element node and one will be a row node. They should look something like the following:

PHP:
struct element_node {
  struct element_node *next;
  int value;
};

struct row_node {
  struct row_node *next;
  struct element_node *value;
}

You could also do it with just one struture where the value member is of type void*. This can cut your code in half, but may require some extra memory management. In C++ you can use templates which will reduce the code work, but may make debugging more confusing.

Next, you'll need to prototype the functions you want to use. The actual functions are up to you, or are probally mentioned in your assignment. If you use structures like the ones above, you will need two sets of functions, one for each structure. Here are some examples.

PHP:
struct element_node* NewElement(int value);
void FreeElements(struct element_node *first);
void InsertElementAfter(struct element_node *node, struct element_node *insert);
void RemoveElement(struct element_node *first, struct element_node *remove);

struct row_node* NewRow();
void FreeRows(struct row_node *first);
void InsertRowAfter(struct row_node *node, struct row_node *insert);
void RemoveRow(struct row_node *first, struct row_node *remove);

Then, in the .c file provide a definition for each of those functions.
 
Without trying to confuse the situation, I have used an array of linked lists to implement a directed graph (also called di-graphs, etc.). If you get really stuck, as a long shot trying search Google for a "directed graph implementation in C", or something like that. You might get lucky and find some information of a linked list of linked lists. Note that there are other ways of implementing graphs than using lists, so yeah its a long shot.
 
Does this work? I am working with an image. I get a picture of rocks black and background white. Basically I have to do a breath search to find each rock and the the pixels that make up that rock. I store the info in a list of lists or a link list of linked list as above. Pixel structure will have my coordinates for each pixel, I do not need an int telling me if it is black or white since I will only store the black pixels.

typedef struct pixel {
int X;
int Y;
} Pixel;

typedef struct branchnode {
Pixel pix;
struct branchnode *next;
} BranchNode;

typedef struct mainnode {
int branch_length;
BranchNode *connect;
struct mainnode *next;
} MainNode;

typedef struct listoflists {
int count;
MainNode *head;
} ListofLists;
 
I understand the element node struct but not the main row node.

The element node, the *next is to go to the next node and the int value is the value at that particular node

struct element_node {
struct element_node *next;
int value;
}

struct row_node {
struct row_node *next;
struct element_node *value;

Why do you have struct element_node *value? Does this go down the row or something?
 
In your row structure, you need two pointers, one to point to the next row , and one to point to the first element on the current row. The row_node pointer points to the next row, and the struct element_node *value points to the first element_node for this row_node.


He used the same variables names in the second struct, which is kinda what's confusing you. It would have been clearer had he used something like this:

'struct row_node {
' struct row_node *next_row;
' struct element_node *thisrow_firstelement;
'}

Make sense?
 
You have it backwords. The next pointer points to the next node in the rows list. The value pointer points to the first element node of a row. In other words, the value for a rows node is the start of another linked list. It may help to pay close attention to the types for each member. row_node.next is of type struct row_node*, so it points to the next row.

The structs you have two posts back should work fine.
 
Back