电影热破武器:我刚学c 编了个程序,改到没错误,没警告,可不能运行,哪个高手帮忙给看看啊

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/06 00:30:44
#include<stdio.h>
#include<stdlib.h>
typedef struct ElemType
{
int cipher;
int location;
}ElemType;
typedef struct Node
{
ElemType data;
struct Node *next;
}NodeType;
typedef struct JosephCircle{
NodeType* head;
NodeType* tail;
int Size;
}JosephCircle;
int MakeNode(NodeType * p,ElemType* e)
{

p=(NodeType*)malloc(sizeof(NodeType));
if(!p) return 0;
p->data=*e;p->next=0;return 1;

}
void FreeNode(NodeType * p)
{
free(p);
}
int InitCircle(JosephCircle* L)
{
(L->head)=(L->tail)=(NodeType*)malloc(sizeof(NodeType));
if(!(L->tail)) exit(0);
((L->tail)->next)=(L->head);
(L->Size)=0;return 1;
}
void AddEnd(JosephCircle* L,NodeType * p)
{
((L->tail)->next)=p;
(L->tail)=p;
(p->next)=(L->head);
}
int Empty(JosephCircle* L)
{
if((L->head)==(L->tail)) return 1;
return 0;
}
int DelAfter(JosephCircle * L,NodeType * p,ElemType * e)
{
NodeType * q;
if(Empty(L)) return 0;
if((p->next)==(L->tail))
{
*e=((L->tail)->data);
FreeNode(L->tail);
(L->tail)=p;
(p->next)=(L->head);
}
else if(p==(L->tail))
DelAfter(L,(L->head),e);
else {
q=p->next;
*e=q->data;
(p->next)=(q->next);
FreeNode(p);
}
(L->Size)--;
return 1;
}

void MakeCircle(JosephCircle* L)
{
int i; ElemType e;int n;
NodeType* p =0;
printf("Input the size of the circle\n");
scanf("%d",&n);
printf("Input the cipher\n");
for(i=1;i<=n;i++)
{
scanf("%d",&(e.cipher));
e.location=i;
MakeNode(p,&e);
AddEnd(L,p);
}
}
void VisitCircle(JosephCircle* L,int a[])
{
int m,i,n=1;NodeType* p=L->tail;ElemType e;
printf("Input the begining location");
scanf("%d",&m);a[0]=(L->Size);
while(!Empty(L))
{
for(i=1;i<m;)
{
if(p==(L->tail))
p=(p->next);
else{
p=(p->next);
i++;
}
}
DelAfter(L,p,&e);
a[n++]=e.location;
}
}
void PrintOrder(int a[])
{
int i;
for(i=1;i<=a[0];i++)
printf("%d,",a[i]);
}
void Initialization()
{
int i;
for(i=0;i<26;i++)
printf("* ") ;
printf("\n");
printf("MakeCircle--m,VixitCircle--c,PrintOrder--p,Quit--Q\n");
for(i=0;i<26;i++)
printf("* ");
printf("\n");
printf("Enter a operation code: m v p q\n");
}
void ReadCommand(char *cmd)
{
printf("Command:");
scanf("%c",cmd);
printf("\n");
}
void InterpretCommand(char cmd)
{
JosephCircle* L=0;int a[30];
InitCircle(L);
switch(cmd)
{
case'm':MakeCircle(L);break;
case'v':VisitCircle(L,a);break;
case'p':PrintOrder(a);break;

}
}
void main()
{
char cmd;
Initialization();
do{
ReadCommand(&cmd);
InterpretCommand(cmd);
}while(cmd!='q');
}

我运行了一下没有错误,要屏幕截图的话回复。可能你的tc有问题吧