注册 登录
编程论坛 数据结构与算法

头插法输入输出

龙岩花界 发布于 2018-12-27 19:19, 2725 次点击
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<iostream.h>
typedef int Elemtype;
typedef struct  LNode
{
    typedef data;
    struct  LNode *next;
}LinkNode;
void CreateListF(LinkNode *&L,Elemtype a[],int n)
{   
    LinkNode *s;
    L=(LinkNode *)malloc(sizeof(LinkNode));
    L->next=NULL;
    for(int i=0;i<n;i++)
    {
    s=(LinkNode *)malloc(sizeof(LinkNode));
    s->data=a[i];
    s->next=L->next;
    L->next=s;
    }
}
void DispList(LinkNode *L)
{
    LinkNode *p=L->next;
    while(p!=NULL)
    {
        printf("%d",p->data);
        p=p->next;
    }
    printf("\n");
}
void main()
{
   LinkNode *L;
   int n=3;
   int a[]={1,2,3};
   CreateListF(L,a,n);
   DispList(L);
}
哪里错了??修改下,大神们
3 回复
#2
林月儿2019-01-05 20:35
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<iostream.h>

typedef int Elemtype;
typedef struct  LNode
{
    typedef data;
#3
蔓草2019-04-11 07:32
void CreateListF(LinkNode *&L,Elemtype a[],int n)
弄清一下指针和引用;
#4
rachelliyuer2019-04-16 11:09
typedef struct  LNode
{
    typedef data;
    struct  LNode *next;
}LinkNode;
该结构体中的data成员的类型应为Elemtype,而不是typedef。
1