2020-04-30

今天学习了链表的应用,其重要功能是可以节省内存,每次存储室需要按条件提前申请储存空间,而不是统一的内存大小,可以灵活运用空间,更加少的占用内存。

作业

#include<stdio.h>

#include<stdlib.h>

struct stu

{

int a;

struct stu *next;

}b;

int main()

{

struct stu *head,*temp,*mid;

int ss=0;

head=(struct stu *)malloc(sizeof(struct stu));

if(head==NULL)

{

printf("filed;\n");

return 0;

}

temp=head;

temp->a=1;

temp->next=(struct stu *)malloc(sizeof(struct stu));

temp->next->a=1;

temp->next->next=(struct stu *)malloc(sizeof(struct stu));

temp->next->next->a=2;

temp->next->next->next=(struct stu *)malloc(sizeof(struct stu));

temp->next->next->next->a=3;

temp->next->next->next->next=(struct stu *)malloc(sizeof(struct stu));

temp->next->next->next->next->a=5;

temp->next->next->next->next->next=(struct stu *)malloc(sizeof(struct stu));

temp->next->next->next->next->next->a=4;

temp->next->next->next->next->next->next=(struct stu *)malloc(sizeof(struct stu));

temp->next->next->next->next->next->next->a=6;

temp->next->next->next->next->next->next->next=NULL;

temp=head;

while(temp->next!=NULL)

{

ss=0;

mid=temp;

while(mid->next!=NULL)

{

if(temp->a==mid->next->a)

{

mid->next=mid->next->next;

ss=1;

break;

}

mid=mid->next;

}

if(ss==0)

{

temp=temp->next;

}

}

temp=head;

while(temp!=NULL)

{

printf("%d ",temp->a);

temp=temp->next;

}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。