0

Answered # Double Linked List

Hello. I am having a tough time understanding the concept of double linked list. For now, i understand double linked list has 2 links, one forward and another one previous. data is in the middle. when inserting must check where to insert. if previous is equal to null, then can insert it to previous. Set the previous to be equal to the newly allocated node. I am looking to do a bubble sort using double linked list. I want to understand the concept first then I can do it. Can someone give some usefule links or explain me the concept? Thank you.

nitin1 15 Discussion Starter Vedoo nitin1 15 Discussion Starter Vedoo Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

0

firsly read Click Here. after reading this, Click Here, then if there is any doubt left, feel free to ask here only. thanks. ;)

0

Thank you for the links....if a newnode is added using a malloc() and the insertion is done in the beginning, so the previous should be null and head->next would be null, right?...How about the next insertion? I did a bit but not working....not sure if is correct.

```
typedef struct nodes
{
int value;
struct nodes *prev;
struct nodes *next;
}node;
node *newnode, *current=head,*previous;
printf("\nHow many integers to insert? ");
scanf ("%d", &num);
{
for (i=0;i<num;i++)
{
printf("\nEnter integer %d: ",i+1);
scanf("%d", &number);
newnode=malloc(sizeof(node));
if (newnode==NULL)
{
printf("\n\nUnable to allocate memory");
exit(EXIT_FAILURE);
}
newnode->value=number;
newnode->next=current;
if (head==NULL)
{
head=newnode;
head->prev=NULL;
previous->next=newnode;
}
else
{
newnode->next=head;
head->prev=newnode;
}
newnode=newnode->next;
}
```

0

see, I want you to do the work. here goes the hint! Take the head insertion as the special case and do it the main() only. okay ? now, then make a function and pass the info part which you want to store in the node. okay ? now, then with each node update the pointer where you need to insert the node, like after head, update a temp pointer with temp==temp->next where temp is equal to the head initially. okay ? So do it n number of times. :-) got it ?

P.S this is one way linked list explaination. for double linked list, nothing difficiult! just have one more pointer which will point to the previous nothing else. but i wana advice you that first try one way linked list, then update it to double linked list. it will be better for you. thanks

*Edited 4 Years Ago by nitin1*

0

I have updated my code as the one I post was wrong. Its working. All I had to do is to complete the insertion into the tail and checking the value of the first node with the second while i iterate the list until it is lesser than the list size.

This question has already been answered. Start a new discussion instead.

Recommended Articles

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

the function that I created to find the ...