#include <iostream> #include <stdio.h> using namespace std; #define size 1000 struct node{ int num; node *next; node *pre; }; node NodeListPool[size]; int index = 0; node nil; node *NIL; void init() { NIL = & nil; NIL->next = NIL; NIL->pre = NIL; NIL->num = -100; } node *getNewNode() { return &NodeListPool[index++]; } void insert(node *target, node *newNode) { newNode->next = target->next; newNode->pre = target; target->next = newNode; newNode->next->pre = newNode; } node *search(int key) { node *tmp = NIL->next; while(tmp != NIL && tmp ->num != key) { tmp = tmp -> next; } return tmp; } void deleteNode(node *node) { node->pre->next = node->next; node->next->pre = node->pre; } int main() { init(); node *tmpNode = NIL; for(int i = 0; i < 100 ;i++) { int tmp = rand()%100 + 1; cout << tmp << endl; node *newNode = getNewNode(); newNode ->num = tmp; insert(tmpNode,newNode); tmpNode = tmpNode->next; } cout << "-------------------------------------"<< endl; tmpNode = NIL; while(tmpNode->next != NIL) { cout << tmpNode->next->num << endl; tmpNode = tmpNode->next; } return 0; }