上午
学了链表,去做了道题目:
但是没做出来。。。。
#include<stdio.h>
#include<stdlib.h>
struct node
{
int num;
struct node *next;
};
int main()
{
struct node *head1,*head2;
struct node *p1,*s,*p2;
int m,n;
int data;
head1=(struct node *)malloc(sizeof(struct node));
head1->next=NULL;
p1=head1;
scanf("m=%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&data);
s=(struct node *)malloc(sizeof(struct node));
s->num=data;
s->next=p1->next;
p1->next=s;
p1=s;
}
head2=(struct node *)malloc(sizeof(struct node));
head2->next=NULL;
p2=head2;
getchar();
scanf("n=%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&data);
s=(struct node *)malloc(sizeof(struct node));
s->num=data;
s->next=p2->next;
p2->next=s;
p2=s;
}
p1->next=head2->next;
struct node *p;
p=head1->next;
while(p!=NULL)
{
printf("%d ",p->num);
p=p->next;
}
return 0;
}
主要问题出现在内存超限,还没有找到哪里导致了内存超限,导致内存超限的原因有很多种:数组越界、内存单元没有初始化便使用、内存没有释放等,明天会从这几个方向去研究。
下午
刷洛谷,但还是一道题都刷不出来,对搜索和链表内容都不够深入了解,然后就去看了会书还有视频,感觉效果不太理想,但还算有收获。明天再改一下链表和电梯的代码,希望能过。