赞
踩
#include <iostream> using namespace std; typedef struct LNode{ int data; struct LNode *pre,*next; }Node, *LinkList; void Init_Linklist(LinkList &s){ s = new Node; s->next = s->pre = NULL; } void create_LinkList(LinkList &s,int n){ Node *p,*r; r = s; for(int i=0;i<n;i++){ p = new Node; p->data = i+1; p->next=p->pre=NULL; r->next = p; p->pre = r; r = p; } r->next = s; s->pre = r; } int insert_Node(LinkList &s,int n,int elem){ Node *p = s; int i=1; while(p && i<n){ p = p->next; i++; } if(!p) return -1; Node *q = new Node; q->data = elem; q->pre = q->next = NULL; if(!p->next) { p->next = q; q->pre = p; q->next = s; s->pre = q; } else{ q->pre = p; q->next = p->next; p->next->pre = q; p->next = q; } } void show(LinkList s){ Node *p = s->next; while(p){ cout<<p->data<<" "; p = p->next; } } int main(){ LinkList s; Init_Linklist(s); create_LinkList(s,5); insert_Node(s,6,10); //show(s); cout<<s->pre->data; return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。