代码拉取完成,页面将自动刷新
#include <iostream>
#include <string>
#include "LineQueue.h"
using namespace std;
LineQueue::LineQueue()
{
front = NULL;
rear = NULL;
}
void LineQueue::enqueue(string newdata)
{
queueNode *s = new queueNode();
s->data = newdata;
s->next = NULL;
if(rear == NULL)
{
front = s;
rear = s;
}
else
{
rear->next = s;
rear = rear->next;
}
}
string LineQueue::dequeue()
{
queueNode *s = front;
string retval = s->data;
if(isEmpty())
{
cout << "Error: The queue is empty." << endl;
}
else
{
if(front == rear)
{
front = NULL;
rear = NULL;
}
else
{
front = front->next;
}
delete(s);
return retval;
}
}
string LineQueue::getFront()
{
if(front == NULL)
{
return "";
}
return front->data;
}
int LineQueue::length()
{
queueNode *p = front;
int len = 0;
while(p != NULL)
{
len++;
p = p->next;
}
return len;
}
bool LineQueue::isEmpty()
{
if(front == NULL) return true;
return false;
}
void LineQueue::showAll()
{
if(isEmpty())
{
cout << "Empty." << endl;
}
else
{
queueNode *p = front;
int i = 1;
while(p != NULL)
{
cout<<i++<<". "<<p->data<<endl;
p = p->next;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。