我的代码的头文件和源文件是这样的:停车场管理的:
base.h:
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <math.h>
#include <process.h>
#include <conio.h>
#define OK 1
#define ERROR 0
#define STACKSIZE 100
#define STACKINCREMENT 10
typedef struct node
{
char no[7];
int time;
}Carnode;
链队列.h:
#include"base.h"
typedef struct QNode
{
char no[7];
int time;
struct QNode *next;
}QNode,*Queueptr;
typedef struct
{
Queueptr front;
Queueptr rear;
}Linkqueue;
int Initqueue(Linkqueue &q);
int DestroyQueue(Linkqueue &q);
int Queuelength(Linkqueue q);
int Enqueue(Linkqueue &q,Carnode e);
int Dequeue(Linkqueue &q,Carnode &e);
顺序栈.h:
#include"base.h"
typedef struct zhan
{
Carnode *base;
Carnode *top;
int stacksize;
}Sqstack;
int Initstack (Sqstack &s);
int Destroystack (Sqstack &s);
int Stacklength (Sqstack s);
int Gettop (Sqstack s,Carnode &e);
int Push(Sqstack &s,Carnode e);
int Pop(Sqstack &s,Carnode &e);
顺序栈.c:
#include "顺序栈.h"
#include"base.h"
int Initstack (Sqstack &s)
{
s.base=(Carnode *)malloc(STACKSIZE*sizeof(Carnode));
if (!s.base)
exit(0);
s.top=s.base;
s.stacksize=STACKSIZE;
return OK;
}
int Destroystack (Sqstack &s)
{
free (s.base);
s.top=s.base;
s.stacksize=0;
return OK;
}
int Stacklength (Sqstack s)
{
return s.top-s.base;
}
int Gettop (Sqstack s,Carnode &e)
{
if (s.top==s.base)
return ERROR;
e=*(--s.top);
return OK;
}
int Push(Sqstack &s,Carnode e)
{
if (s.top-s.base>=s.stacksize)
{
s.base=(Carnode *)realloc(s.base,(s.stacksize+STACKSIZE)*sizeof(Carnode));
if (!s.base)
exit (0);
s.top=s.base+s.stacksize;
s.stacksize=s.stacksize+STACKSIZE;
}
*(s.top++)=e;
return OK;
}
int Pop(Sqstack &s,Carnode &e)
{
if (s.top==s.base)
return ERROR;
e=*--s.top;
return OK;
}
链队列.c:
#include"链队列.h"
#include"base.h"
int Initqueue(Linkqueue &q)
{
q.front=q.rear=(Queueptr)malloc(sizeof(QNode));
if(!q.front)
exit(0);
q.front->next=NULL;
return OK;
}
int DestroyQueue(Linkqueue &q)
{
while(q.front)
{
q.rear=q.front->next;
free(q.front);
q.front=q.rear;
}
return OK;
}
int Queuelength(Linkqueue q)
{
return q.rear-q.front;
}
int Enqueue(Linkqueue &q,Carnode e)
{
Queueptr p;
p=(Queueptr)malloc(sizeof(QNode));
if(!p)
exit(0);
p->no=e->no;
p.time=e.time;
p->next=NULL;
q.rear->next=p;
q.rear=p;
return OK;
}
int Dequeue(Linkqueue &q,Carnode &e)
{
Queueptr p;
if (q.front==q.rear)
return ERROR;
p=q.front->next;
e.no=p->no;
e.time=p.time;
q.front->next=p->next;
if (q.rear==p)
q.rear=q.front;
free(p);
return OK;
}
望众人手帮忙!