双向链表数据输出错误
[code=C/C++][/code]
#include "iostream"
#include "stdlib.h"
#define OK 1
#define ERROR -1
typedef int Elemtype;
typedef int Stutaus;
using namespace std;
typedef struct DuLNode
{
int data;
struct DuLNode *next,*prior;
}DuLNode,*DuLinkList;
void Create_L(DuLinkList &L,int n)
{
L=(DuLinkList)malloc(sizeof(DuLNode));
L->next=L->prior=L;
for(int i=n;i>0;--i)
{
DuLNode *p=(DuLinkList)malloc(sizeof(DuLNode));
cin>>(p->data);
//p->next=L->next;
//L->next=p;
p->prior=L->next;
p=L->prior;
L->prior=p->next;
L=p->prior;
//p=L->next->prior;
//L->next->prior=p;
}
}
void Print_L(DuLinkList &L,int n)
{
DuLinkList p;
int i=0;
p=L;
while (i<n)
{
++i;
//p=p->next;
cout<<p->data;
}
cout<<endl;
}
void main()
{
int n;
DuLinkList La;
cout<<"please input data num: "<<endl;
cin>>n;
Create_L(La,n);
cout<<"data is:"<<endl;
Print_L(La,n);
} |