Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard
akanksha wrote:3. Plz explain me your words-
(a) ''First of all, how do you represent an empty list? Is it a pointer to NULL? Or is it a pointer to a link that points to NULL? This has to be decided. If you pick the first option, then there is something wrong with the prototypes, and you should be passing around double pointers to `struct link''.
-----This as you did in the sample program.You passed the address of the pointer and then used double pointers.This is how we should access the list?
(b)If it is the second, it's kind of ugly that the first node (the one that acts as the header of the list) has a unused `info' field. Something about this design smells bad, and I think you should replace the first node with a struct of a different type, which represents the header of a list (which you can identify with the list itself).
-------How can we replace the first node with the different type of struct?All the variables creating the list has to be of the similiar types! Not understood ?. Plz make a function illustrating this.
4.In your sample program-
push_node_at_the_head(node **list, int data)
If I do-------push_node_at_the_head(node *list, int data) and in main-
push_node_at_the_head(list, 1);
Then if this also a bad idea?I mean this you have also used in the print function,so why don't you think it good?
akanksha wrote:[...]Here i m posting the previous program but only the creation and display function of the program, which is not running proprely.
I want to confirm that in your program there is no 'start' node (which has only the addess of the first node, and not any data filed).
What do you mean by that? What input are you using, what happens and what did you expect to happen?
The first thing you should do is write a program that just does the input, without using a linked list at all. You just ask for a list of integers and you just print each integer back as you read it (to make sure that you are reading them correctly), and then you ask if the user wants to continue. Once you get that working, you can try to write the function that you really want.
That's correct. And as I said before, it might be a good idea to have a header for the linked list, but it would be of a different type.
akanksha wrote:Alvaro ,Are you talking about the basic program of taking in the integers and printing back what is taken?
I know this little program. If still you wanna see then I ll upload......
Also I dont know how to use fgets.I mean I have read about this but only the defination and its working. It inolves opening of a file, so how should I do that. Also I know Alvaro that it is always better to use good input functions(like fgets,sscanf) but for the time being ,if only it is possible, do with scanf , I m comfortable with that. Once the basic program is made I ll try to switch over to these functions.
That's correct. And as I said before, it might be a good idea to have a header for the linked list, but it would be of a different type.
Sorry Alvaro, im still not getting how to attach that header. you took 'unsigned size'. I mean, to have a header which will contain the address.it should be a pointer! Plz give a small code explaining this. Hope you wont mind that.
typedef struct {
node *head;
node *tail;
unsigned size;
} linked_list;Return to Algorithms & Data Structures
Users browsing this forum: No registered users and 1 guest