标签:efi int let col node def ini div using
#include <bits\stdc++.h> using namespace std; typedef long long ll; struct Node{ int key; Node *next,*prev; }; Node *nil; void init(){ nil = (Node *) malloc(sizeof(Node)); nil->next = nil; nil->prev = nil; } void insert(int key){ Node *x = (Node *) malloc(sizeof(Node)); x->key = key; //在头结点后添加元素 x->next = nil->next; nil->next->prev = x; nil->next = x; x->prev = nil; } Node *listSearch(int key){ Node *cur = nil->next; // 从头结点后面的元素开始访问 while(cur != nil && cur->key != key){ cur = cur->next; } return cur; } void deleteNode(Node *t){ if(t == nil) return; // t为头结点时不作处理 t->prev->next = t->next; t->next->prev = t->prev; free(t); } void deleteFirst(){ deleteNode(nil->next); } void deleteLast(){ deleteNode(nil->prev); } void deleteKey(int key){ //删除搜索到的结点 deleteNode(listSearch(key)); } void printList(){ Node *cur = nil->next; int isf = 0; while(true){ if(cur == nil) break; if(isf++ > 0) printf(" "); printf("%d",cur->key); cur = cur->next; } printf("\n"); } int main() { return 0; } // writen by zhangjiuding
标签:efi int let col node def ini div using
原文地址:http://www.cnblogs.com/zhangjiuding/p/7637961.html