Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
wildwoong@gmail.com committed Jan 24, 2011
1 parent d69fc49 commit 89f03b2
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions LinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
template <typename T>
class LinkedList {
public:
class Node {
class Node
{
friend LinkedList;
public:
Node()
Expand Down Expand Up @@ -404,37 +405,39 @@ LinkedList<T>::Node* LinkedList<T>::Delete()
template <typename T>
LinkedList<T>::Node* LinkedList<T>::Delete(Node* index)
{
this->current = index;

if(this->length > 1)
{
if(this->current == this->head)
if(index == this->head)
{
this->current->next->previous = this->current->next;
this->head = this->current->next;
}
else if(this->current == this->tail)
index->next->previous = index->next;
this->head = index->next;
this->current = 0;
}
else if(index == this->tail)
{
this->current->previous->next = this->current->previous;
this->tail = this->current->previous;
}
index->previous->next = index->previous;
this->tail = index->previous;
this->current = this->tail;
}
else
{
this->current->next->previous = this->current->previous;
this->current->previous->next = this->current->next;
index->next->previous = index->previous;
index->previous->next = index->next;
this->current = this->current->previous;
}
}
}
else
{
this->head = 0;
this->tail = 0;
this->current = 0;
}

if(this->current != 0)
if(index != 0)
{
delete this->current;
this->current = 0;
delete index;
}

this->length--;

return this->current;
Expand Down

0 comments on commit 89f03b2

Please sign in to comment.