热爱学习的呆萌的文青
2015-12-18 03:16c语言单向链表的问题???
#include<stdio.h>
#include<stdlib.h>
struct node{
int num;
struct node *next;
};
//构建空的链表
struct node* InitList(struct node *L){
L = (struct node*)malloc(sizeof(struct node));
L = NULL;
printf_s("InitList sucess!");
return L;
}
//创建单链表
struct node* CreateList(struct node *L,int n){
struct node *temp,*p;
L = (struct node*)malloc(sizeof(struct node));
L->next = NULL;
temp=L;
for (int i = 0; i < n; i++){
p = (struct node*)malloc(sizeof(struct node));
scanf_s("%d", &p->num);
temp->next = p;
temp = p;
}
temp->next = NULL;
return L;
}
void PrintList(struct node *L){
struct node *temp = L;
while (temp != NULL){
printf_s("%d", temp->num);
temp = temp->next;
}
}
void PrintMenu(){
printf_s("------Menu------\n");
printf_s("0 InitList\n");
printf_s("1 CreateList\n");
printf_s("2 PrintList\n");
}
void main(){
int n,c;
struct node *La;
PrintMenu();
printf_s("Enter the command: ");
scanf_s("%d", &c);
switch (c){
case 0:
La = InitList(La);
break;
case 1:
printf_s("Enter the number of LinkList: ");
scanf_s("%d", &n);
La = CreateList(La, n);
break;
case 2:
PrintList(La);
break;
default:
printf_s("ERROR,Enter again: ");
break;
}
system("pause");
}
为什么主函数case 0 的La = InitList(La); 这句报错: error C4700: uninitialized local variable 'La' used。 ????
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- C语言程序,单向动态链表删除结点,使用free(),报错 Trace/breakpoint trap
- c语言
- 1个回答
- 数据结构实验:单链表
- c语言
- 1个回答
- 输入若干个正整数(输入-1为结束标志),建立一个单向链表,将其中的偶数值结点删除后输出。
- c语言
- c++
- 1个回答
- 怎样将一个单向链表的首尾调换
- c
- c语言
- 2个回答
- C语言单链表的插入求解了
- c
- 指针
- 链表
- 单链表
- 4个回答
换一换