My teacher taught us everything about linked list except how the code looks like. Could someone show me how to initialize a linked list in C?
How do you initialize a simple linked list in C?
first, include list.h
Then create a list with a line like
list%26lt;int%26gt; myList;
where int is the data type and myList is whatever you want to call it.
Then you can use myList to access all the list commands. To go through a list, you need to create an iterator.
list%26lt;int%26gt;::iterator iterator_name;
see the source for more info...
Reply:hello, linked list program is very complicate to write with this. i will give some notes about it and you try in your class. actually the initialization of the linked list means, the first node of the list should be null.
when make enter a new node then the FIRST pointer should point the first node and address of the first node should be null. this is the actual meaning.
to initialize a linked list, make the FIRST pointer as NULL. when you want to add the first node, then create an object for Node structure and assain the new value to the newly created node.
then make the address of the new node as NULL so that it cant see another next node. this means that the first node is you are created. also there is no more nodes in the list.
this is the logic. you try with you lab to solve the problem what your teacher asked. if you want to increase the level of your programming, then you should find the logic. its enough to program well. the program for the logic you shold do it in your own. dont expect to someone to give the exact code to help you. all are ready to give some logic to you to program.
you should be ready to program for the logic. this will help you to start program at the time you see the problem. OK?
__Vasantha kumar
Reply:A linked list is simply a chain of structures which contain a pointer to the next element.
Using malloc function you need to initialize the linked list node
sample
struct node* head = NULL;
head= malloc(sizeof(struct node));
the following link will help you to find more info.
http://cslibrary.stanford.edu/103/
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment