链表
Posted T技术沙龙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了链表相关的知识,希望对你有一定的参考价值。
#include "stdio.h"
#include "stdlib.h"
struct Student
int n;
struct Student *next;
;
int main()
struct Student *head;
void create(struct Student**);
struct Student* proceed(struct Student*);
void print(struct Student*);
void del(struct Student*);
create(&head);
print(head);
head=proceed(head);
print(head);
del(head);
return 0;
void create(struct Student **p)
struct Student *p1,*p2;
int i,n;
printf("Please input n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
p1=(struct Student*)malloc(sizeof(struct Student));
p1->n=i;
if(i==1)
*p=p1;
else
p2->next=p1;
p2=p1;
p1->next=NULL;
void print(struct Student *head)
struct Student *p=head;
while(p!=NULL)
printf("%d ",p->n);
p=p->next;
printf("/n");
struct Student* proceed(struct Student *head)
struct Student *p1,*p2,*t;
p1=p2=head;
p1=p1->next;
while(p1!=NULL)
t=p1->next;
p1->next=p2;
if(p2==head)
p2->next=NULL;
p2=p1;
p1=t;
head=p2;
return head;
void del(struct Student*head)
struct Student *p1,*p2;
p1=head;
while(p1!=NULL)
p2=p1;
p1=p1->next;
free(p2);
以上是关于链表的主要内容,如果未能解决你的问题,请参考以下文章
力扣——链表题 203.移除链表元素83.删除排序链表中重复元素82.删除排序链表中重复元素Ⅱ206.反转链表 876.链表的中间节点