循环链表实现 /(ㄒoㄒ)/~~ 太不容易了!!! 值得纪念!!!
// 10.2.1链表实现 !!!! 太不容易了 /(ㄒoㄒ)/~~ !!!!
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
struct node *create( int n ); //构建循环链表
void myfree( struct node *head,int n ); //释放循环链表,其中n为链表的结点个数
void print( struct node *head,int n ); //打印循环链表的一轮,其中nwei链表的结点个数
int delete_list( struct node *head,int n,int s ); //实现题目的内容
int main()
{
struct node *head;
int n,s,i,len;
printf("请输入有多少人,从第几人开始报数!\n");
scanf("%d%d",&n,&s);
head=create( n );
printf("未删除的结点:\n");
print( head,n );
printf("\n");
len=delete_list( head,n,s );
printf("\nlen=%d\n",len);
myfree( head,n );
return 0;
}
//构建循环链表,在链尾插入
struct node *create( int n )
{
int i=0;
struct node *p,*head,*tail;
head=NULL;
while( i<n ){
p=( struct node * )malloc( sizeof( *p ) );
p->next=NULL;
p->data=i+1;
if( head==NULL ) head=tail=p;

本文介绍了设有n个人围坐一圈,从第s个人开始报数,报到m的人出列的循环过程,通过循环链表来实现这一算法。文章作者分享了在构建和释放链表过程中遇到的挑战,以及链表相对于数组的灵活性优势。

3756

被折叠的 条评论
为什么被折叠?



