Hello everyone,
This is the part where I try to insert a node to a circular double linked list.
my struct is
Code:
struct doubleList{
int id;
struct doubleList *prev;
struct doubleList *next;
};
typedef struct doubleList DoubleList;
typedef DoubleList *DoubleListPtr;
I get a SEGME at line 26.
I can you give the whole file, if you would like to try running it.
But I would be grateful mostly if I understood where the problem is!
Do you see something that i dont??
Thanks in advance..!
Code:
/*********************************************/
1void init(DoubleListPtr start, int *id){
2 start->prev = start;
3 start->id = *id;
4 start->next = start;
5}
6
7/*********************************************/
8void DL_insert(DoubleListPtr startPtr, int *id){
9 DoubleListPtr new_node, current;
10
11 new_node = malloc(sizeof(DoubleList));
12 if ( new_node != NULL ){
13 init( new_node, id);
14 printf("tha valoume to new_node->id : %d\n ", new_node->id);
15 current = startPtr;
16 printf("lLLLLLLLLLLLLLLLLLLLLLLLL **current->id: %d\n", current->id);
17 printf("3\n");
18 while( (current->next != startPtr) && (*id > current->id) && (current->id != NULL) ){ /* find where the new node gets in*/
19 printf("Node comes after **current->id: %d\n", current->id);
20 current = current->next;
21 }
22 printf("4\n");
23 new_node->next = current->next; /* Start is being copied */
24 printf("5\n");
25
26 (current->next)->prev = new_node;
27 printf("6\n");
28
29 current->next = new_node;
30 printf("7\n");
31
32 new_node->prev = current;
33 printf("8\n");
34
35 }else{
36 printf("Problem with malloc, func DL_insert() \n");
37 }
38 printf("--please print my id %d\n",new_node->id);
39}
Bookmarks