實習 C 實現資料結構停車場

2021-10-04 10:21:38 字數 3804 閱讀 4754

停車場的標頭檔案

(1)停車場需要設計的各種資料結構類,包括順序棧,鏈式佇列,車輛資訊

(2)其中兩個資料結構因為常用,所以設計為模板,包含了初始化,增加資料,刪除資料的函式,可以直接套用其他資料型別

#pragma once

#define maxsize 2

template

<

typename t>

class

stackls;~

stackls()

;void

push

(t data)

; t pop

(t data);}

;template

<

typename t>

inline

void stackls

::push

(t data)

}template

<

typename t>

inline t stackls

::pop

(t data)

return data;

}template

<

typename t>

class

lnode

//鏈式佇列宣告,儲存待進入停車場的車輛

;template

<

typename t>

class

linkqueue

;template

<

typename t>

inline

void linkqueue

::creat()

//必須初始化!

template

<

typename t>

inline

void linkqueue

::(t dat)

template

<

typename t>

inline t linkqueue

::delete_queue()

t info = p-

>data;

free

(p);

return info;

}template

<

typename t>

inline

int linkqueue

::order()

return a;

}class

carinfo

;carinfo

(char status,

char

* license,

int hour,

int minute)

;void

parking

(stackls

*stack_lots, linkqueue

* waitint_queue)

;//停車判斷入後出

intfind_licen

(stackls

*stack_lots,

char

* licen)

;//出車庫查詢其位置

void

waiting

(linkqueue

* waiting_queue,

int statue, stackls

* stack_lots)

;//便道等待車輛

void

temp_stack

(stackls

*stack_lots,

int find_number)

;//臨時棧調出其他擋路車輛

void

time_money

(carinfo &car_in)

;//計算**,形參為找到的車輛資訊

carinfo operator=(

const carinfo &c)

};

停車場的cpp檔案

(1)車輛資訊加入停車場

(2)多餘車輛轉移到鏈式佇列

(3)車輛離開停車場

(4)鏈式佇列的車輛彈出再加入停車場

// parkinglots.cpp : 定義控制台應用程式的入口點。

//#include

"stdafx.h"

#include

"muban.h"

#include

#include

using

namespace std;

carinfo::

carinfo

(char sta,

char

* lice,

int hr,

int mi)

void carinfo::

parking

(stackls

*stack_lots, linkqueue

* waitint_queue)

else

if(stack_lots-

>top >= maxsize)

}elseif(

this

->status ==

'd'||

this

->status ==

'd')

else

if(stack_lots-

>top >0)

else

if(find_num +

1!= stack_lots-

>top)

if(waitint_queue-

>front-

>next !=

null)}

}}int carinfo::

find_licen

(stackls

* stack_lots,

char

* licen)

}return a;

}void carinfo::

waiting

(linkqueue

* waiting_queue,

int statue, stackls

* stack_lots)

}void carinfo::

temp_stack

(stackls

* stack_lots,

int find_number)

temp-

>

push

(dri_in);}

while

(temp-

>top !=0)

cout <<

" 在您後面進入了 "

<< maxsize - find_number -

1<<

" 輛車,需要讓其他車輛先倒出來…………\n"

; cout <<

" 現在已經將你的車輛挪出來啦!\n";}

void carinfo::

time_money

(carinfo & car_in)

if(period_hour ==0)

}if(period_minute >=60)

cout <<

"\n車牌號為 "

<<

this

->license<<

" 的車輛停車時長為: "

<< period_hour <<

"小時"

<< period_minute <<

"分鐘";}

intmain()

return0;

}

資料結構 停車場管理

問題描述 設停車場是乙個可停放n輛汽車的狹長通道,且只有乙個大門可供汽車進出。汽車在停車場內按車輛到達時間的先後順序,依次由北向南排列 大門在最南端,最先到達的第一輛車放在車場的最北端 若車場內已停滿n輛汽車,則後來的汽車只能在門外的便道上等待,一旦有車開走,則排在便道上的第一輛車即可開入 當停車場...

資料結構 停車場管理

題目 設停車場內只有乙個可停放n輛汽車的狹長通道,且只有乙個大門可供汽車進出 汽車在停車場內按車輛到達時間的先後順序,依次由北向南排列 大門在最南端,最先到達的第一輛車停放在車場的最北端 若車場內已停滿n輛汽車,則後來的汽車只能在門外的便道上等候,一旦有車開走,則排在便道上的第一輛車即可開入 當停車...

資料結構 停車場管理

二 概要設計 三 詳細設計 四 除錯分析 五 使用者手冊 六 測試結果 停車場是乙個可停放n輛汽車的狹長通道,且只有乙個大門可供汽車進出。汽車在停車場內按車輛到達時間的先後順序,依次由北向南排列 大門在最南端,最先到達的第一輛車放在車場的最北端 若車場內已停滿n輛汽車,則後來的汽車只能在門外的便道上...