第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

求大佬幫助

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
class Customer
{
public:
??? Customer(string name,int age);
??? Customer();
??? void printInfo()const;
private:
??? string m_strName;
??? int m_iAge;
};
Customer::Customer(string name, int age)
{
?m_strName = name;
?m_iAge = age;
}
Customer::Customer()
{
??? m_strName = "null";
??? m_iAge = 0;
}
void Customer::printInfo()const
{
??? cout<<m_strName<<" : "<<m_iAge<<endl;
}

class Queue
{
private:
??? Customer* m_pQueue;????????? //隊(duì)列數(shù)組指針
??? int m_iQueueLen;?????????? //隊(duì)列數(shù)組長度
??? int m_iQueueCapacity;????? //隊(duì)列數(shù)組容量
??? int m_iHead;
??? int m_iTail;

public:
??? Queue(int queueCapacity)//創(chuàng)建隊(duì)列
??? {
??????? m_pQueue = new Customer[m_iQueueCapacity];
??????? ClearQueue();
??????? m_iQueueCapacity = queueCapacity;

??? }
??? virtual ~Queue()????????? //銷毀隊(duì)列
??? {
??????? delete []m_pQueue;
??????? m_pQueue = NULL;
??? }
??? void ClearQueue()???????? //清空隊(duì)列
??? {
??????? m_iHead = 0;
??????? m_iTail = 0;
??????? m_iQueueLen = 0;
??? }
??? bool QueueEmpty() const?? //判空隊(duì)列
??? {
??????? if(m_iQueueLen == 0){
??????????? return true;
??????? }
??????? else return false;
??? }
??? bool QueueFull() const??? //判斷是否為滿
??? {
??????? if(m_iQueueLen == m_iQueueCapacity){
??????????? return true;
??????? }
??????? else return false;
??? }
??? int QueueLength() const?? //隊(duì)列長度
??? {
??????? return m_iQueueLen;
??? }
??? bool EnQueue(Customer element) //新元素入列
??? {
??????? if(QueueFull())
??????? {
??????????? return false;
??????? }
??????? else
??????? {
??????????? m_pQueue[m_iTail] = element;
??????????? m_iTail++;
??????????? m_iQueueLen++;
??????????? m_iTail = m_iTail % m_iQueueCapacity;
??????????? return true;
??????? }
??? }
??? bool DeQueue(Customer &element)//首元素出列
??? {
??????? if(QueueEmpty())
??????? {
??????????? return false;
??????? }
??????? else
??????? {
??????????? element = m_pQueue[m_iHead];
??????????? m_iHead++;
??????????? m_iQueueLen--;
??????????? return true;
??????? }
??? }
??? void QueueTraverse()????? //遍歷隊(duì)列
??? {
??????? for(int i = m_iHead;i < m_iQueueLen + m_iHead;i++)
??????? {
??????????? cout << "前面還有" << (i-m_iHead) << "個人" <<endl;
??????????? m_pQueue[i % m_iQueueCapacity].printInfo();
??????? }
??? }

};
int main()
{
??? Queue *p = new Queue(4);
??? Customer c1("Letme",1);
??? Customer c2("Uzi",2);
??? Customer c3("Ming",3);
??? Customer c4("Mlxg",4);
??? p->EnQueue(c1);
??? cout<<"?"<<endl;
??? p->EnQueue(c2);
??? p->EnQueue(c3);
??? p->EnQueue(c4);
??? p->QueueTraverse();
??? return 0;
}


這段代碼的遍歷和其他都沒問題,但是往里面加數(shù)據(jù)時無法成功加入


正在回答

1 回答

我也看了半天,發(fā)現(xiàn)問題出在這里,

? Queue(int queueCapacity)//創(chuàng)建隊(duì)列
??? {
??????? m_pQueue = new Customer[m_iQueueCapacity];//這里的m_iQueueCapacity并沒有初始值,無法分配數(shù)組,應(yīng)該是筆誤,應(yīng)該改成queueCapacity
??????? ClearQueue();
??????? m_iQueueCapacity = queueCapacity;

??? }

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
數(shù)據(jù)結(jié)構(gòu)探險—隊(duì)列篇
  • 參與學(xué)習(xí)       110141    人
  • 解答問題       183    個

與現(xiàn)實(shí)最為貼近的數(shù)據(jù)結(jié)構(gòu)-隊(duì)列,帶大家進(jìn)入數(shù)據(jù)結(jié)構(gòu)的美妙世界

進(jìn)入課程
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號