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日

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化