106 lines
No EOL
1.7 KiB
C++
106 lines
No EOL
1.7 KiB
C++
#include "list.h"
|
|
|
|
List::List()
|
|
{
|
|
_size = 0;
|
|
|
|
header->data = 0;
|
|
header->succ = trailer;
|
|
header->pred = NULL;
|
|
|
|
trailer->succ = NULL;
|
|
trailer->pred = header;
|
|
}
|
|
|
|
Node List::predInsert(Node Old, int New)
|
|
{
|
|
Node T = new node;
|
|
T->data = New;
|
|
T->succ = Old;
|
|
T->pred = Old->pred;
|
|
Old->pred = T;
|
|
_size++;
|
|
return T;
|
|
}
|
|
Node List::succInsert(Node Old, int New)
|
|
{
|
|
Node T = new node;
|
|
T->data = New;
|
|
T->pred = Old;
|
|
T->succ = Old->succ;
|
|
Old->succ = T;
|
|
_size++;
|
|
return T;
|
|
}
|
|
void List::firstInsert(int New)
|
|
{
|
|
Node T = new node;
|
|
T->data = New;
|
|
T->pred = header;
|
|
T->succ = header->succ;
|
|
header->succ = T;
|
|
_size++;
|
|
}
|
|
void List::lastInsert(int New)
|
|
{
|
|
Node T = new node;
|
|
T->data = New;
|
|
T->succ = trailer;
|
|
T->pred = trailer->pred;
|
|
trailer->pred = T;
|
|
_size++;
|
|
}
|
|
Node List::predInsertN(Node Old, Node New)
|
|
{
|
|
Node T = new node;
|
|
T = New;
|
|
T->succ = Old;
|
|
T->pred = Old->pred;
|
|
Old->pred = T;
|
|
_size++;
|
|
return T;
|
|
}
|
|
Node List::succInsertN(Node Old, Node New)
|
|
{
|
|
Node T = new node;
|
|
T = New;
|
|
T->pred = Old;
|
|
T->succ = Old->succ;
|
|
Old->succ = T;
|
|
_size++;
|
|
return T;
|
|
}
|
|
|
|
Node List::firstInsertN(Node New)
|
|
{
|
|
Node T = new node;
|
|
T = New;
|
|
T->pred = header;
|
|
T->succ = header->succ;
|
|
header->succ = T;
|
|
_size++;
|
|
return T;
|
|
}
|
|
Node List::lastInsertN(Node New)
|
|
{
|
|
Node T = new node;
|
|
T = New;
|
|
T->succ = trailer;
|
|
T->pred = trailer->pred;
|
|
trailer->pred = T;
|
|
_size++;
|
|
return T;
|
|
}
|
|
Node List::find(int i)
|
|
{
|
|
Node ans = first();
|
|
for (int i = 0; i < _size; i++)
|
|
{
|
|
ans = ans->succ;
|
|
}
|
|
return ans;
|
|
}
|
|
int List::get(int i)
|
|
{
|
|
return find(i)->data;
|
|
} |