筛选号码(c语言版)

 时间:2026-02-15 11:38:15

1、#include<stdio.h>

#include <stdlib.h>

typedef struct node{

struct node *next;

int data;

}LinkList;

LinkList *CreatListH(int n)

{

LinkList *L,*S,*head;

int num=n-1;

L=(LinkList*)malloc(sizeof(LinkList));

head=L;

head->data=n;

L->next=head;

while(num>=1)

{

S=(LinkList*)malloc(sizeof(LinkList));

S->data=num;

S->next=L->next;

L->next=S;

num--;

}

return head;

}

LinkList *Count(LinkList *head)

{

LinkList *p,*u;

int count=0;

    p=head;

while(p->next!=p)

{

count++;

p=p->next;

if(count==2)

{

u=p->next;

p->next=u->next;

free(u);

count=0;

}

}

printf("%d\n",p->data);

}

int main()

{

LinkList *head;

int n;

scanf("%d",&n);

    head=CreatListH(n);

Count(head);

return 0;

}

筛选号码(c语言版)

2、本题采用链表遍历的方法,根据题意每遍历3个,则删除第三个结点的数据。删除到最后所剩的一个即为所求,链表采用单向循环链表。

while(p->next!=p)

{

count++;

p=p->next;

if(count==2)//此处删除的是p->next,所以是2

{

u=p->next;

p->next=u->next;

free(u);

3、此外采用头插法创建链表,为符合题目意思,在链表中存储数据时,数据逆序存储,如果采用尾插法,则顺序存储即可。

LinkList *CreatListH(int n)

{

LinkList *L,*S,*head;

int num=n-1;

L=(LinkList*)malloc(sizeof(LinkList));

head=L;//所有节点都存储数据

head->data=n;

L->next=head;

while(num>=1)

{

S=(LinkList*)malloc(sizeof(LinkList));

S->data=num;

S->next=L->next;

L->next=S;

num--;//逆序存储

}

  • 产品包装的作用
  • 加减档通过有诀窍,油门离合的关系要像跷跷板!
  • 旅游微信小程序模式介绍
  • 英雄联盟疾风剑豪(亚索)的上分技巧
  • 考研专业课真题如何找
  • 热门搜索
    成语意思 lunar是什么意思 fire是什么意思 词类活用是什么意思 碉堡什么意思 ais是什么意思 相生相克是什么意思 智慧是什么意思 阳台吊顶用什么材料好 什么叫数据库