Mar 17, 2019 at 7:30pm
Time to learn about debuggers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
$ g++ -Wall -Wextra -g foo.cpp
foo.cpp: In function ‘int main()’:
foo.cpp:19:24: warning: unused variable ‘position’ [-Wunused-variable]
int choice, value, position;
^
$ gdb -q ./a.out
Reading symbols from ./a.out...done.
(gdb) run
Starting program: /home/sc/Documents/a.out
Operations on Doubly linked list
1.Create doubly linked list
2.Print from start
3.Print from end
1
Enter value: 22
Operations on Doubly linked list
1.Create doubly linked list
2.Print from start
3.Print from end
3
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400bf3 in reverse_display_dlist () at foo.cpp:88
88 cout<<temp->data<<" ";
(gdb) p temp
$1 = (node *) 0x0
(gdb) list
83 struct node *temp = head;
84 while(temp != NULL){
85 temp = temp->next;
86 }
87 do{
88 cout<<temp->data<<" ";
89 temp = temp->prev;
90 }while(temp != head);
91
92 cout<<endl;
(gdb)
|
Your first while loop needs to stop at the last node, not fall off the end.
Last edited on Mar 17, 2019 at 7:30pm
Mar 17, 2019 at 7:43pm
Better.
Now do it without using any global variables.
Mar 17, 2019 at 8:13pm
Okay, I will try.
Would it be hard to remove global variables later?
I want to finish the whole program using my method first.