58 lines
1 KiB
C++
58 lines
1 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#define Node node *
|
|
|
|
typedef struct node
|
|
{
|
|
int data;
|
|
Node pred;
|
|
Node succ;
|
|
} node;
|
|
|
|
class List
|
|
{
|
|
private:
|
|
Node header = new node;
|
|
Node trailer = new node;
|
|
int _size;
|
|
|
|
protected:
|
|
Node firstInsertN(Node New);
|
|
Node lastInsertN(Node New);
|
|
Node succInsertN(Node old, Node ne);
|
|
Node predInsertN(Node old, Node ne);
|
|
void removeN(Node i);
|
|
Node searchN(int value,int n,Node p);
|
|
|
|
public:
|
|
int getSize()
|
|
{
|
|
return _size;
|
|
}
|
|
List();
|
|
~List();
|
|
void clear();
|
|
Node first() { return header->succ; }
|
|
Node last() { return trailer->pred; }
|
|
int firstInsert(int New);
|
|
int lastInsert(int New);
|
|
Node succInsert(Node Old, int New);
|
|
Node predInsert(Node Old, int New);
|
|
|
|
int get(int i);
|
|
Node find(int i);
|
|
int remove(int i);
|
|
Node searchN(int value,int n);
|
|
int valid(Node p);
|
|
|
|
|
|
void sort();
|
|
|
|
int operator[](int i)
|
|
{
|
|
Node p = first();
|
|
while (0 < i--)
|
|
p = p->succ;
|
|
return p->data;
|
|
}
|
|
};
|