This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/DataStructure/Code/ex05/list.h
2022-01-03 16:09:11 +08:00

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;
}
};