动态链表

//洛谷P1996
#include<bits.stdc++.h>
struct node{
       int data;
	   node *next;
};
int main(){
    int n,m;sacnf("%d %d",&n,&m);
	node *head,*p,*now,*prev;
	head = new node ;head->data=1;head->next=NULL;
	now = head;
	for(int i=2;i<=n;i++){
	   p=new node;p->data=i;p->next=NULL;
	   now->next=p;
	   now=p;
	}
	now->next=head;
	now=head,prev=head;
	while((n--)>1){
	   for(int i=1;i<m;i++){
	      prev now;
		  now=now->next;
	   }
	   printf("%d",now->data);
	   prev->next=now->next;
	   delete now;
	   now = prev ->next;
	}
	printf("%d",now->data);
	delete now;
	return 0;

全部评论

相关推荐

06-12 16:23
已编辑
小米_软件开发(准入职员工)
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务