【数据结构 _双向链表_List_0960】双向链表的操作问题

来源:互联网 发布:淘宝旺旺手机版卖家版 编辑:程序博客网 时间:2024/05/21 17:14
#include <stdio.h>#include <stdlib.h>#include <algorithm>#include <iostream>using namespace std;typedef struct node{int data;struct node *next;struct node *prior;}List;void createList(List *&L,int n,int a[]){List *r,*s;int i;L=(List *)malloc(sizeof(List));r=L;for(i=0;i<n;i++){s=(List *)malloc(sizeof(List));s->data=a[i];r->next=s;s->prior=r;//前方注意双向链表;r=s;}r->next=NULL;}void disList(List *L){List *p=L->next;while(p!=NULL){cout<<p->data<<" ";p=p->next;}}int main(){List *L;int num;cin>>num;int a[1005];int i;for(i=0;i<num;i++)cin>>a[i];sort(a,a+num);createList(L,num,a);disList(L);return 0;}

0 0