《发生肾么事了之链表CE》
  • 板块学术版
  • 楼主van_Dijk
  • 当前回复5
  • 已保存回复5
  • 发布时间2022/5/4 15:19
  • 上次更新2023/10/28 02:11:37
查看原帖
《发生肾么事了之链表CE》
644697
van_Dijk楼主2022/5/4 15:19

RT。

最近比较颓,指针太拉了,所以随便打了个链表板子。

结果。。。

CE!

求大家调一调,代码如下:

#include<bits/stdc++.h>
using namespace std;

struct node
{
	int data;//这个节点的数
	struct node *next;//下一个节点
};

int main()
{
	struct *head,*q,*p,*t;
	head=NULL;
	int n,a;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&n);
        p=(struct node *)malloc(sizeof(struct node));
		p->data=a;
		p->next=NULL;
		if(head==NULL)
			head=p;
		else
			q->next=p;
		q=p;
	}
	cin>>a;
	t=head;
	while(t!=NULL)
	{
		if(t->next==NULL || t->next->data > a)
		{
			p=(struct node *)malloc(sizeof(struct node));
			p->data=a;
			p->next=t->next;
			t->next=p;
		}
		t=t->next;
	}
	t=head;
	while(t!=NULL)
	{
		printf("%d ",t->data);
		t=t->next;
	}
	return 0;
}

码风应该还好吧,望大家查一下!

CE提示(洛谷ide测的):

/tmp/compiler_00iwb1w7/src: 在函数‘int main()’中:
/tmp/compiler_00iwb1w7/src:19:11: 错误:cannot convert ‘node*’ to ‘int*’ in assignment
   19 |         p=(struct node *)malloc(sizeof(struct node));
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |           |
      |           node*
/tmp/compiler_00iwb1w7/src:20:20: 错误:对成员‘data’的请求出现在‘* p’中,而后者具有非类类型‘int20 |                 p->data=a;
      |                    ^~~~
/tmp/compiler_00iwb1w7/src:21:20: 错误:对成员‘next’的请求出现在‘* p’中,而后者具有非类类型‘int21 |                 p->next=NULL;
      |                    ^~~~
/tmp/compiler_00iwb1w7/src:25:28: 错误:对成员‘next’的请求出现在‘* q’中,而后者具有非类类型‘int25 |                         q->next=p;
      |                            ^~~~
/tmp/compiler_00iwb1w7/src:32:23: 错误:对成员‘next’的请求出现在‘* t’中,而后者具有非类类型‘int32 |                 if(t->next==NULL || t->next->data > a)
      |                       ^~~~
/tmp/compiler_00iwb1w7/src:32:40: 错误:对成员‘next’的请求出现在‘* t’中,而后者具有非类类型‘int32 |                 if(t->next==NULL || t->next->data > a)
      |                                        ^~~~
/tmp/compiler_00iwb1w7/src:34:27: 错误:cannot convert ‘node*’ to ‘int*’ in assignment
   34 |                         p=(struct node *)malloc(sizeof(struct node));
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                           |
      |                           node*
/tmp/compiler_00iwb1w7/src:35:28: 错误:对成员‘data’的请求出现在‘* p’中,而后者具有非类类型‘int35 |                         p->data=a;
      |                            ^~~~
/tmp/compiler_00iwb1w7/src:36:28: 错误:对成员‘next’的请求出现在‘* p’中,而后者具有非类类型‘int36 |                         p->next=t->next;
      |                            ^~~~
/tmp/compiler_00iwb1w7/src:36:36: 错误:对成员‘next’的请求出现在‘* t’中,而后者具有非类类型‘int36 |                         p->next=t->next;
      |                                    ^~~~
/tmp/compiler_00iwb1w7/src:37:28: 错误:对成员‘next’的请求出现在‘* t’中,而后者具有非类类型‘int37 |                         t->next=p;
      |                            ^~~~
/tmp/compiler_00iwb1w7/src:39:22: 错误:对成员‘next’的请求出现在‘* t’中,而后者具有非类类型‘int39 |                 t=t->next;
      |                      ^~~~
/tmp/compiler_00iwb1w7/src:44:33: 错误:对成员‘data’的请求出现在‘* t’中,而后者具有非类类型‘int44 |                 printf("%d ",t->data);
      |                                 ^~~~
/tmp/compiler_00iwb1w7/src:45:22: 错误:对成员‘next’的请求出现在‘* t’中,而后者具有非类类型‘int45 |                 t=t->next;
      |                      ^~~~

谢谢大家!

2022/5/4 15:19
加载中...