苏嵌实战 学习日志4

姓名 : 施樊凯 日期 :2018.09.06
今日学习任务
制作停车场系统
今日学习系统完成情况
main.c

#include"park.h"

int main()
{
    char choice[16] = {0};

    stack park_stack,leaving_stack;
    queue wait_queue;

    welcome();

    init(&park_stack,&leaving_stack,&wait_queue);   //初始化栈和队列

    while(1)
    {
        menu();
        printf("选择功能: \n");
        memset(choice,0,8);     //清空
        scanf("%s",choice);

        switch(choice[0])
        {
            case '1':
                EnterPark(&park_stack,&wait_queue);
                break;
            case '2':
                OutPark(&park_stack,&leaving_stack,&wait_queue);
                break;
            case '3':
                ShowParkInfo(&park_stack);
                break;
            case '4':
                ShowWaitInfo(&wait_queue);
                break;
            case '5':
                bye();
                break;

park.c

#include<stdio.h>
#include"park.h"

void welcome()
{
    system("clear");    //清除屏幕
    printf("\n\n\n");
    printf("**********************************\n");
    printf("*****************欢迎*************\n");
    printf("**********************************\n");
    sleep(2);
}

void menu()
{
    system("clear");
    printf("\n\n\n");
    printf("\t\t 1、停车\n");
    printf("\t\t 2、出车\n");
    printf("\t\t 3、场内车辆信息\n");
    printf("\t\t 4、等候车辆信息\n");
    printf("\t\t 5、退出系统\n");
}


void bye()
{
    system("clear");
    printf("\t\t\t byebye!!\n");
    exit(1);    //退出程序
}

//初始化停车栈,让路栈,等候队列
void init(stack *s1,stack *s2,queue *q)
{
    int ret;
    ret = InitStack(s1);
    if(FAILURE == ret)
    {
        printf("Init Stack Failure!\n");
    }

    ret = InitStack(s2);
    if(FAILURE ==ret)
    {
        printf("Init Stack Failure!\n");
    }

park.h

#ifndef PARK_H
#define PARK_H


#include<time.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>

#define MAXSIZE 5
#define SUCCESS 1000
#define FAILURE 1001
#define FULL    1002


struct CarInfo  //保存车辆信息
{
    char id[32];   //车牌号
    time_t t;  //停车时间

};
typedef struct CarInfo info;



struct Stack    //停车/让路栈
{
    info CarData[MAXSIZE];
    int top;

};
typedef struct Stack stack;


struct Node  //表示等候队列结点信息
{
    char id[32];
    struct Node *next;  //指针域

};
typedef struct Node node; //等候队列

struct Queue
{
    node *front;  //队头指针
    node *rear;
};
typedef struct Queue queue;
void welcome();
void menu();
void bye();
int InitQueue(queue *q);
void init(stack * s1,stack *s2,queue *q);
int InitStack(stack *s);
void EnerQueue(queue *q,char *id);
int push(stack *s,char *id);
void ShowParkInfo(stack *s);
void ShowWaitInfo(queue *q);
char *pop(stack *s);
int EmptyStack(stack *s);
int EmptyQueue(queue *q);
ch

queue.c

#include "park.h"

int InitQueue(queue *q)
{
    if (NULL == q)
    {
        return FAILURE;
    }
    node *p = (node *)malloc(sizeof(node));   //分配头结点
    if(NULL == p)
    {
        return FAILURE;
    }

    p -> next =NULL;


    //队头指针和队尾指针同时指向头结点

    q -> front = q -> rear =p;
    return SUCCESS;
}

    int EnterQueue(queue * q,char *id)
    {
        if(NULL == q || NULL == id)
        {
            return FAILURE;
        }

        node *p =(node * ) malloc(sizeof (node));
        if(NULL == p)
        {
            return FAILURE;

        }
        strcpy(p -> id,id);
        p ->next =NULL;

        q ->rear ->next = p;
        q ->rear = p;
        return SUCCESS;

    }

int EmptyQueue(queue *q)
    {
    if(NULL ==q)
    {
        return FAILURE;
    }
    return (q->front == q->rear) ? SUCCESS:FAILURE;
    }

char *DelQueue(queue *q)
{
    if(NULL == q)
    {
        return NULL;
    }
    char *id =(char *)malloc(32);
    if(NULL

stack.c

#include "park.h"

int InitStack(stack *s)
{
    if(NULL == s)
    {
        return FAILURE;
    }

    s -> top = -1; //初始化成空栈

    return SUCCESS;
}


int push(stack *s,char *id)
{
    if(NULL == s || NULL == id)
    {
        return FAILURE;
        //入参判断
    }
    if(s -> top == MAXSIZE -1)
    {
        return FULL;
    }

    strcpy(s -> CarData[s -> top +1].id,id);
    s -> CarData[s -> top+ 1].t = time(NULL);

    s -> top ++;

今日遇到的问题
代码编译出现bug

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值