主题:[讨论]帮忙看看我的程序哪里错误了,
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define MAX 20
typedef struct CarT;
typedef struct QueuePosT;
typedef struct QueueT;
/*This structer is showing the car information*/
typedef struct CarT
{
char *carNO;
char *arrive;
int pos;
};
/* This is queue structer*/
typedef struct QueueT
{
struct CarT car;
struct QueueT *next;
};
/* This is the queue postion*/
typedef struct QueuePosT
{
struct QueueT *front;
struct QueueT *rear;
};
/*This function initalised the queue*/
void InitQueue(struct QueuePosT *T)
{
T->front=T->rear=(struct QueueT*)malloc(sizeof(struct QueueT));
if(T->front==NULL)
{
printf("There isn't any memory!");
exit(1);
}
T->rear->next=NULL;
}
/*This function judged the queue is empty*/
int EmpQueue(struct QueuePosT *T)
{
if(T->front==T->rear)
return 1;
else
return 0;
}
/*This function is destroyed the queue*/
void DesQueue(struct QueuePosT *T)
{
while(T->front)
{
T->front=T->rear;
T->rear=NULL;
free(T->front);
}
}
/*This function is enter element */
void EnQueue(struct QueuePosT *T,struct CarT *e)
{
struct QueueT* p;
p=(struct QueueT*)malloc(sizeof(struct QueueT));
if(p==NULL)
{
printf("There isn't any memeory for the node!");
exit(1);
}
p->car.arrive=e->arrive;
p->car.carNO=e->carNO;
p->car.pos=e->pos;
p->next=NULL;
T->rear->next=p;
T->rear=p;
}
/*This function is deleted the element */
struct CarT DelQueue(struct QueuePosT *T)
{
struct CarT e;
struct QueueT *p;
if(EmpQueue(T))
exit(1);
p=T->front->next;
e.arrive=p->car.arrive;
e.carNO=p->car.carNO;
e.pos=p->car.pos;
T->front->next=p->next;
if(p==T->rear)
T->front=T->rear;
free(p);
return e;
}
/*Enter car funtion*/
void Enter(struct QueuePosT *T)
{
struct CarT E;
int i,n;
printf("Enter you want to enter nO;");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the car NO: ");
scanf("%s",&E.carNO);
printf("Enter the arrived time: ");
scanf("%s",&E.arrive);
printf("Enter the car position: ");
scanf("%d",E.pos);
EnQueue(T,&E);
}
}
/*Delete Car function*/
void Delete(struct QueuePosT *T)
{
struct CarT e;
int i,n;
printf("Enter you want to delete:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
e=DelQueue(T);
printf("##################\n");
printf("%s--||--",e.arrive);
printf("%s--||--",e.carNO);
printf("%d\n",e.pos);
printf("@@@@@@@@@@@@@@@@@@\n");
}
}
/*main funtcion*/
int main()
{
struct QueuePosT B;
int n;
InitQueue(&B);
printf("\tEnter you want to do: \n");
while(n)
{
printf("\t1---Enter The car:\n");
printf("\t2---Delete the Car: \n");
printf("\t3---Clear all car:\n");
printf("\t Enter any other number quit the program!\n");
scanf("%d",&n);
switch(n)
{
case 1:Enter(&B);break;
case 2:Delete(&B);break;
case 3:DesQueue(&B);break;
default:
{printf("Quit the program!");
n=0;
break;
}
}
}
}
是一个对列的程序,编译无错误,请好心人帮忙运行一下,看到的错误帮我解决了,谢谢啊,
#include <malloc.h>
#include <stdlib.h>
#define MAX 20
typedef struct CarT;
typedef struct QueuePosT;
typedef struct QueueT;
/*This structer is showing the car information*/
typedef struct CarT
{
char *carNO;
char *arrive;
int pos;
};
/* This is queue structer*/
typedef struct QueueT
{
struct CarT car;
struct QueueT *next;
};
/* This is the queue postion*/
typedef struct QueuePosT
{
struct QueueT *front;
struct QueueT *rear;
};
/*This function initalised the queue*/
void InitQueue(struct QueuePosT *T)
{
T->front=T->rear=(struct QueueT*)malloc(sizeof(struct QueueT));
if(T->front==NULL)
{
printf("There isn't any memory!");
exit(1);
}
T->rear->next=NULL;
}
/*This function judged the queue is empty*/
int EmpQueue(struct QueuePosT *T)
{
if(T->front==T->rear)
return 1;
else
return 0;
}
/*This function is destroyed the queue*/
void DesQueue(struct QueuePosT *T)
{
while(T->front)
{
T->front=T->rear;
T->rear=NULL;
free(T->front);
}
}
/*This function is enter element */
void EnQueue(struct QueuePosT *T,struct CarT *e)
{
struct QueueT* p;
p=(struct QueueT*)malloc(sizeof(struct QueueT));
if(p==NULL)
{
printf("There isn't any memeory for the node!");
exit(1);
}
p->car.arrive=e->arrive;
p->car.carNO=e->carNO;
p->car.pos=e->pos;
p->next=NULL;
T->rear->next=p;
T->rear=p;
}
/*This function is deleted the element */
struct CarT DelQueue(struct QueuePosT *T)
{
struct CarT e;
struct QueueT *p;
if(EmpQueue(T))
exit(1);
p=T->front->next;
e.arrive=p->car.arrive;
e.carNO=p->car.carNO;
e.pos=p->car.pos;
T->front->next=p->next;
if(p==T->rear)
T->front=T->rear;
free(p);
return e;
}
/*Enter car funtion*/
void Enter(struct QueuePosT *T)
{
struct CarT E;
int i,n;
printf("Enter you want to enter nO;");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the car NO: ");
scanf("%s",&E.carNO);
printf("Enter the arrived time: ");
scanf("%s",&E.arrive);
printf("Enter the car position: ");
scanf("%d",E.pos);
EnQueue(T,&E);
}
}
/*Delete Car function*/
void Delete(struct QueuePosT *T)
{
struct CarT e;
int i,n;
printf("Enter you want to delete:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
e=DelQueue(T);
printf("##################\n");
printf("%s--||--",e.arrive);
printf("%s--||--",e.carNO);
printf("%d\n",e.pos);
printf("@@@@@@@@@@@@@@@@@@\n");
}
}
/*main funtcion*/
int main()
{
struct QueuePosT B;
int n;
InitQueue(&B);
printf("\tEnter you want to do: \n");
while(n)
{
printf("\t1---Enter The car:\n");
printf("\t2---Delete the Car: \n");
printf("\t3---Clear all car:\n");
printf("\t Enter any other number quit the program!\n");
scanf("%d",&n);
switch(n)
{
case 1:Enter(&B);break;
case 2:Delete(&B);break;
case 3:DesQueue(&B);break;
default:
{printf("Quit the program!");
n=0;
break;
}
}
}
}
是一个对列的程序,编译无错误,请好心人帮忙运行一下,看到的错误帮我解决了,谢谢啊,