Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
double_linked_list Class Reference

Public Member Functions

void insert (int x)
 
void remove (int x)
 
void search (int x)
 
void show ()
 
void reverseShow ()
 

Constructor & Destructor Documentation

◆ double_linked_list()

double_linked_list::double_linked_list ( )
inline
13{ start = NULL; }

Member Function Documentation

◆ insert()

void double_linked_list::insert ( int x)
21 {
22 node *t = start;
23 if (start != NULL) {
24 while (t->next != NULL) {
25 t = t->next;
26 }
27 node *n = new node;
28 t->next = n;
29 n->prev = t;
30 n->val = x;
31 n->next = NULL;
32 } else {
33 node *n = new node;
34 n->val = x;
35 n->prev = NULL;
36 n->next = NULL;
37 start = n;
38 }
39}
struct node { int data; int height; struct node *left; struct node *right;} node
for std::queue
Definition avltree.cpp:13
Definition binary_search_tree.cpp:11

◆ remove()

void double_linked_list::remove ( int x)
41 {
42 node *t = start;
43 while (t != NULL && t->val != x) {
44 t = t->next;
45 }
46 if (t == NULL) {
47 return;
48 }
49 if (t->prev == NULL) {
50 if (t->next == NULL) {
51 start = NULL;
52 } else {
53 start = t->next;
54 start->prev = NULL;
55 }
56 } else if (t->next == NULL) {
57 t->prev->next = NULL;
58 } else {
59 t->prev->next = t->next;
60 t->next->prev = t->prev;
61 }
62 delete t;
63}

◆ reverseShow()

void double_linked_list::reverseShow ( )
89 {
90 node *t = start;
91 while (t != NULL && t->next != NULL) {
92 t = t->next;
93 }
94 while (t != NULL) {
95 std::cout << t->val << "\t";
96 t = t->prev;
97 }
98}

◆ search()

void double_linked_list::search ( int x)
65 {
66 node *t = start;
67 int found = 0;
68 while (t != NULL) {
69 if (t->val == x) {
70 std::cout << "\nFound";
71 found = 1;
72 break;
73 }
74 t = t->next;
75 }
76 if (found == 0) {
77 std::cout << "\nNot Found";
78 }
79}

◆ show()

void double_linked_list::show ( )
81 {
82 node *t = start;
83 while (t != NULL) {
84 std::cout << t->val << "\t";
85 t = t->next;
86 }
87}

The documentation for this class was generated from the following file: