请问:为什么运行不了呀?代码问题是:
统计单链表中偶数位序的元素和并输出元素值
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
typedef struct Node
{
int data;
struct Node*next;
}Node,*LinkList;
void Initlist(LinkList &L)
{
L=(Node*)malloc(sizeof(Node));
L->next=NULL;
}
void Creatlist(LinkList &L,int a[100],int n)
{
L= (Node *)malloc(sizeof(Node));
L->next = NULL;
LinkList p;
for (int i = 0; i < n; i++) {
p = (LinkList )malloc(sizeof(LinkList));
p->data = a[i];
p->next = L->next;
L->next=p;
}
}
int deleteList (LinkList &L,int m)
{
LinkList q = L;
if(m<1)
{
printf("error\n");
return 0;
}
int i=0;
LinkList p;
while(q!=NULL&&i<m)
{
i++;
q=q->next;
}
p=q->next;
q->next=p->next;
free(p);
return 1;
}
void OutputList(LinkList &L)
{
LinkList s;
s=L->next;
while(s)
{
cout<<s->data<<' ';
s=s->next;
}
}
int main()
{
int n,m,a[100];
cin>>n;
LinkList L;
Initlist(L);
Creatlist(L,a,n);
cin>>m;
if(deleteList(L,m))
OutputList(L);
if(L->next==NULL)
cout<<"null";
return 0;
}