1 Star 0 Fork 0

白白白白白烛葵/data_structure

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LineQueue.cpp 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
#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;
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/icesummer/data_structure.git
git@gitee.com:icesummer/data_structure.git
icesummer
data_structure
data_structure
master

搜索帮助