我在网上查到的建双链表都定义了类,我忘记太多了具体建立双链表我知道原理了,但是为什么要建立对象呢?下面是我的代码,报错了很多书上明明就是这样打的啊
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef struct people
{
int data;
struct poeple *pr;
struct poeple *next;
}plink;
void creatlink (plink* &ahua,int a[],int n){
plink *s;
ahua=(plink *)malloc(sizeof(plink)) ;
ahua->pr=ahua->next=NULL;
for(int i=0;i<n;i++)
{
s=(plink*)malloc(sizeof(plink));
s->data=a[i];
s->next=ahua->next;
if(ahua->next!=NULL)
{
ahua->next->pr=s;
ahua->next=s;
s->pr=ahua;
}
}
}int main
{ int a[25];
for(int n=0;n<25;n++)
{
a[n]=n+2;
}
plink ahua;
creatlink(ahua,a[],n);
return 0;
}