# Algorithms_in_C++: double_linked_list Class Reference

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

{ start = NULL; }

## Member Function Documentation

## insert()

void double_linked_list::insert | ( | int | x | ) |

{
node *t = start;
if (start != NULL) {
while (t->next != NULL) {
t = t->next;
}
node *n = new node;
t->next = n;
n->prev = t;
n->val = x;
n->next = NULL;
} else {
node *n = new node;
n->val = x;
n->prev = NULL;
n->next = NULL;
start = n;
}
}
node
Definition: avltree.cpp:13

## remove()

void double_linked_list::remove | ( | int | x | ) |

{
node *t = start;
while (t != NULL && t->val != x) {
t = t->next;
}
if (t == NULL) {
return;
}
if (t->prev == NULL) {
if (t->next == NULL) {
start = NULL;
} else {
start = t->next;
start->prev = NULL;
}
} else if (t->next == NULL) {
t->prev->next = NULL;
} else {
t->prev->next = t->next;
t->next->prev = t->prev;
}
delete t;
}

## reverseShow()

void double_linked_list::reverseShow | ( |  | ) |

{
node *t = start;
while (t != NULL && t->next != NULL) {
t = t->next;
}
while (t != NULL) {
std::cout << t->val << "\t";
t = t->prev;
}
}
std::cout

## search()

void double_linked_list::search | ( | int | x | ) |

{
node *t = start;
int found = 0;
while (t != NULL) {
if (t->val == x) {
std::cout << "\nFound";
found = 1;
break;
}
t = t->next;
}
if (found == 0) {
std::cout << "\nNot Found";
}
}

## show()

void double_linked_list::show | ( |  | ) |

{
node *t = start;
while (t != NULL) {
std::cout << t->val << "\t";
t = t->next;
}
}

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

- data_structures/doubly_linked_list.cpp