-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_ll.cpp
49 lines (42 loc) · 1.4 KB
/
test_ll.cpp
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
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#include "linkedlist.h"
int main ( )
{
Double_list *list_p;
Double_list *list_n;
list_p = new Double_list ();
/* copy constructor DOES NOT work, or I don't know how to call it.
*/
list_p->item_add ( 7 );
list_p->item_add ( 9 );
list_p->item_add ( 10 );
list_n = new Double_list ( *list_p);
cout << "MEM tests" << endl;
cout << "mem address for 7 in list_n " << list_n->retrieve(7)->next << endl;
cout << "mem address for 7 in list_p " << list_p->retrieve(7)->next << endl;
/* the following retrieve statement seg faults. Since 5 doesn't exist in the list,
* next obviously cannot either. I should throw an exception instead of returning null
*/
cout << "Mem address where 5 is: "<< list_p->retrieve(5) << endl;
cout << "Print tests" << endl;
list_n->print();
list_p->print();
list_p->pop ();
list_p->retrieve( 7 );
cout << "node after 7, should be 9, is it? " << list_p->retrieve(7)->next->item << endl;
list_p->remove ( 9 );
cout << "node after 7, should be a null pointer, is it? " << list_p->retrieve(7)->next << endl;
list_p->item_add ( 1241 );
list_p->remove ( 12 );
list_p->pop();
list_p->pop();
list_p->pop();
list_p->pop();
list_p->pop();
cout << "size: " << list_p->get_length() << endl;
cout << "empty?: " << list_p->is_empty() << endl;
return 1;
}