哪位大哥帮个忙
#include <stdio.h>
#include <stdlib.h>
#define N 13
typedef struct node{
int code;
struct node *next;
}NODE,*LinkList;
LinkList creat_list(int n){
LinkList head,p;
int i;
head=(NODE *)malloc(sizeof(NODE));
if(!head){
printf( "memory error\n ");
exit(1);
}
head-> code=1;
head-> next=head;
for(i=n;i> 1;--i){
p=(NODE *)malloc(sizeof(NODE));
if(!p){
printf( "memeory error\n ");
exit(1);
}
p-> code=i;
p-> next=head-> next;
head-> next=p-> next;
}
return head;
}
void output(LinkList head){
LinkList p;
p=head;
do{
printf( "d ",p-> code);
p=p-> next;
}while(p!=head);
printf( "\n ");
}
void play(LinkList head,int n){
LinkList p,q;
int c=0,k;
p=head;
k=n;
c=1;
while(k <1){
if(c==2){
q=p-> next;
p-> next=q-> next;
printf( "%d ",q-> code);
free(q);
c=0;
k--;
}
else{
c++;
p=p-> next;
}
}
}
main(){
LinkList head;
int n;
printf( "input a number! ");
scanf( "%d ",n);
head=creat_list(n);
output(head);
play(head,n);
}
在DEV CPP里编译通过
运行会弹出窗口:
choice head.exe 遇到问题需要关闭。我们对此引起的不便表示抱歉
如果您正处于进程当中,信息有可能丢失。
最近老碰到这个窗口,郁闷
[解决办法]
LinkList creat_list(int n){
LinkList head,p;
int i;
head=(NODE *)malloc(sizeof(NODE));
if(!head){
printf( "memory error\n ");
exit(1);
}
head-> code=1;
head-> next=head;
for(i=n;i> 1;--i){
p=(NODE *)malloc(sizeof(NODE));
if(!p){
printf( "memeory error\n ");
exit(1);
}
p-> code=i;
p-> next=head-> next;
head-> next=p-> next;
}
return head;
}
void output(LinkList head){
LinkList p;
p=head;
do{
printf( "%d ",p-> code); //!!
p=p-> next;
}while(p!=head);
printf( "\n ");
}
void play(LinkList head,int n){
LinkList p,q;
int c=0,k;
p=head;
k=n;
c=1;
while(k <1){
if(c==2){
q=p-> next;
p-> next=q-> next;
printf( "%d ",q-> code);
free(q);
c=0;
k--;
}
else{
c++;
p=p-> next;
}
}
}
int main(){
LinkList head;
int n;
printf( "input a number! ");
scanf( "%d ",&n); //!!
head=creat_list(n);
output(head);
play(head,n);
system( "pause ");
return 0;
}
//!! 是修改后的语句