shayebudong 发表于 2021-4-18 21:51:38

小白女生快慢指针求助

本帖最后由 shayebudong 于 2021-4-18 21:51 编辑

刚开始学数据结构{:5_103:}第一次琢磨着写单链表,错误比较多,喜欢有老鱼油指点一下{:5_91:}

#include<stdio.h>
#include<stdlib.h>
#define N 20//指向结构体指针类型:struct node*类型的变量

typedef struct Node
{
      int head;

      char date;
}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,并没有出错。

yuxijian2020 发表于 2021-4-19 08:38:16

int main()
{

      int* p,*q,i;
      int* search,* mid;//设置快慢链表,查找链表中间数
      int* e;//e指向中间数结点
      Linklist pre;
      void chushihualist(q);    ----->调用方法的时候不需要前面的void
      
      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;
}

shayebudong 发表于 2021-4-19 20:13:24

yuxijian2020 发表于 2021-4-19 08:38


谢谢大佬!!{:9_228:}我好好研究一下!
页: [1]
查看完整版本: 小白女生快慢指针求助