|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 shayebudong 于 2021-4-18 21:51 编辑
刚开始学数据结构 第一次琢磨着写单链表,错误比较多,喜欢有老鱼油指点一下
#include<stdio.h>
#include<stdlib.h>
#define N 20//指向结构体指针类型:struct node*类型的变量
typedef struct Node
{
int head;
char date[N];
}user;//定义链表
typedef struct node
{
user data;
struct node* next;
}Linklist;
void chushihualist(Linklist* L)
{
L = (Linklist*)malloc(sizeof(Linklist));
L->next = NULL;
};//初始化链表
//void Listinsert(Linklist* L, Linklist* p)
//{
// p->next = L->next;
// L->next = p;
//}
int main()
{
int* p,*q,i;
int* search,* mid;//设置快慢链表,查找链表中间数
int* e;//e指向中间数结点
Linklist pre;
void chushihualist(q);
while (i = 0;i < 20; i++)
{
p->data = rand() % 100 + 1;
q->next = p;
}
//赋值随机数链表
while (search->next != NULL)
{
if (search->next->next != NULL)
{
search->next->next;
mid->next;//search速度是mid的两倍
}
else
{
search->next;
}
}
*e = mid->data;
return 0;
}
以下是错误提示:
error C2143: 语法错误: 缺少“)”(在“;”的前面)
1>E:\程序\C语言\1.helloworld\helloworld.c(55,17): warning C4552: ”<“: 未使用表达式结果
1>E:\程序\C语言\1.helloworld\helloworld.c(55,26): error C2059: 语法错误:“)”
1>E:\程序\C语言\1.helloworld\helloworld.c(56,2): error C2143: 语法错误: 缺少“;”(在“{”的前面)
1>E:\程序\C语言\1.helloworld\helloworld.c(57,6): error C2223: “->data”的左侧必须指向结构/联合
1>E:\程序\C语言\1.helloworld\helloworld.c(58,6): error C2223: “->next”的左侧必须指向结构/联合
1>E:\程序\C语言\1.helloworld\helloworld.c(62,17): error C2223: “->next”的左侧必须指向结构/联合
1>E:\程序\C语言\1.helloworld\helloworld.c(64,15): error C2223: “->next”的左侧必须指向结构/联合
1>E:\程序\C语言\1.helloworld\helloworld.c(66,12): error C2223: “->next”的左侧必须指向结构/联合
1>E:\程序\C语言\1.helloworld\helloworld.c(67,9): error C2223: “->next”的左侧必须指向结构/联合
1>E:\程序\C语言\1.helloworld\helloworld.c(71,12): error C2223: “->next”的左侧必须指向结构/联合
1>E:\程序\C语言\1.helloworld\helloworld.c(76,12): error C2223: “->data”的左侧必须指向结构/联合
很多错误都是关于的-> 符号的,请问是p->还是 *p->呢,个人人为应该是指针指向结点的next,并没有出错。 |
|