【数据结构】双链表
作者:互联网
#include<iostream>
#include<cstdlib>
using namespace std;
typedef struct DuLNode {
int data;
DuLNode *prior,*next;
};
void InitSList(DuLNode *&SL) {//初始化双链表
SL=(DuLNode*)malloc(sizeof(DuLNode));
SL->prior=SL->next=NULL;
}
void createSList(DuLNode *&SL) {//创建双链表
DuLNode *s,*r;
r=SL;
while(1) {
s=( DuLNode*)malloc(sizeof(DuLNode));
cin>>s->data;
if(s->data==-1)break;
r->next=s;
s->prior=r;
r=s;
}
r->next=NULL;
}
void showSList(DuLNode *&SL) { //输出双链表
DuLNode *p=SL->next;
while(p) {
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
int main() {
DuLNode *SL;
InitSList(SL);
createSList(SL);
showSList(SL);
return 0;
}
标签:void,next,DuLNode,SL,双链,数据结构,data 来源: https://blog.csdn.net/wlc19981111/article/details/116230985