Fly.c 2022-03-06 07:14 采纳率: 75%
浏览 21
已结题

c语言动态内存分配问题,Linux平台问题

Linux平台,好像动态内存分配的函数不好使了,无法给链表头节点初始化

img

typedef struct LinkList
{
  char data;
  struct LinkList* next;
}Node,*LinkList;
//初始化单链表,创建一个头指针与一个头结点
Status InitList(LinkList l)
{
  l =(Node*)calloc(1,sizeof(Node));//头结点
  l->next = NULL;//初始化头结点
  l->data = 0;
  return OK;
}
Elemtype InsertList(LinkList l,Elemtype e,int i)//在第i个元素之前插入
{
   if(i<0 || i>Length(l)+1)
       return 0;
    Node* new =(Node*)malloc(sizeof(Node));//新节点
   while(--i)
     l = l->next;
   new->data = e;//节点值
   new->next = l->next;
   l->next = new;
   l->data++;
   return e;
}

Status Create_tail(LinkList l,Elemtype* e,int i)
{
  if(!Empty(l))
      return ERROR;
  int j = 0;
  while(i - j)
  {
    InsertList(l,*(e+j),l->data+1);
    ++j;
  }
  return OK;
}

int main()
{
    int i = 0;
    Elemtype a[10],e;
  LinkList h;
  InitList(h);
  scanf("%s",a);
  Create_tail(h,a,strlen(a));
  DispList(h);
  printf("%d\n",Length(h));
  if(Empty(h))
      printf("此链表为空\n");
  else
      printf("此链表不为空\n");
  GetElem(h,3,&e);
  printf("%c\n",e);
  LocateElem(h,'V');
  InsertList(h,'D',7);
  DispList(h);
  DeleList(h,&e,1);
  DispList(h);
  DestoryList(h);
  return 0;
}

  • 写回答

1条回答 默认 最新

  • 真相重于对错 2022-03-06 09:02
    关注

    参数用二级指针

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月14日
  • 已采纳回答 3月6日
  • 创建了问题 3月6日

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来