神论教主
发表于 2014-1-4 19:53:52
真是难得给力的帖子啊。
柠“萌”圆
发表于 2014-2-11 20:48:49
queue.h#ifndef QUEUE_H_INCLUDED
#define QUEUE_H_INCLUDED
#include <iostream>
#include <new>
template <class T>
class Queue
{
private:
class Node
{
public:
T data;
Node * next;
Node(const T & d) : data(d), next(nullptr) {}
Node() : next(nullptr) {}
};
typedef Node * LinkList;
LinkList front;
LinkList rear;
unsigned int length;
public:
Queue();
~Queue();
bool enqueue(const T & item);
bool dequeue(T & item);
void show()const;
bool is_empty()const { return length == 0;}
unsigned int size()const { return length; }
};
template <class T>
Queue<T>::Queue()
{
front = rear = nullptr;
length = 0;
}
template <class T>
Queue<T>::~Queue()
{
if (front != nullptr)
{
LinkList temp = front;
while (front)
{
front = front -> next;
delete temp;
temp = front;
}
}
}
template <class T>
bool Queue<T>::enqueue(const T & item)
{
if (is_empty())
{
try{
front = rear = new Node(item);
}
catch(std::bad_alloc & ba) {
std::cout << ba.what() << std::endl;
return false;
}
length++;
return true;
}
LinkList add;
try {
add = new Node(item);
}
catch(std::bad_alloc & ba) {
std::cout << ba.what() << std::endl;
return false;
}
rear -> next = add;
rear = add;
length++;
return true;
}
template <class T>
bool Queue<T>::dequeue(T & item)
{
if (is_empty())
return false;
item = front -> data;
LinkList temp = front;
front = front -> next;
delete temp;
if (front == nullptr)
rear = front;
length--;
return true;
}
template <class T>
void Queue<T>::show()const
{
LinkList p = front;
while (p)
{
std::cout << p -> data << " ";
p = p -> next;
}
std::cout << std::endl;
}
#endif // QUEUE_H_INCLUDEDmain.cpp#include <iostream>
#include "queue.h"
int main()
{
Queue<char> triangle;
using std::cout;
using std::endl;
using std::cin;
cout << "请输入一串符号: ";
char ch;
do
{
cin.get(ch);
if (ch != '\n')
triangle.enqueue(ch);
}while(cin && ch != '\n');
char once = '\0'; // 存储前一个字符
cout << "下面按要求打印符号三角形:\n";
if (triangle.is_empty())
return 0;
triangle.show(); // 打印第一行
unsigned int size = triangle.size();
for (unsigned int i = 2; i <= size; i++) // 从第二行开始打印
{
for (unsigned int j = 0; j < i - 1; j++)
cout << " ";
for (unsigned int k = 0; k <= size - i; k++) // 第i行输出size - i + 1个符号
{
char c;
if (once == '\0')
{
triangle.dequeue(c);
triangle.dequeue(ch);
}
else
{
c = once;
triangle.dequeue(ch);
}
if (c == ch)
triangle.enqueue('+');
else
triangle.enqueue('-');
once = ch;
}
triangle.show();
once = '\0';
}
return 0;
}
tt20060428
发表于 2014-3-26 19:27:47
真是被感动的痛哭流涕……
一夜尘埃
发表于 2014-4-14 22:52:02
顶楼主~~~ 哈哈哈
C语言入门
发表于 2014-4-20 11:39:26
楼主加油,鱼C加油!我们都看好你哦!
aicode
发表于 2014-4-22 07:32:37
强烈支持楼主ing……
aicode
发表于 2014-4-22 07:41:09
for( j=0; j < n-i-1; j++ )
{
deleteQueue(&q, &b);
printf("%c ", b);
if( a == b )
{
insertQueue(&q, '+'); // 同号,“+”入队列
}
else
{
insertQueue(&q, '-'); // 异号,“-”入队列
}
a = b;
}
这一段代码什么意思????????????
aicode
发表于 2014-4-22 08:03:06
希望小甲鱼老师能多找一些数据结构的练习题和配上相关算法的视频讲解,激动人心,无法言表!
ccdebug
发表于 2014-4-26 10:16:29
激动人心,无法言表!
青玄
发表于 2014-5-23 12:48:32
激动人心,无法言表!
逆流杀
发表于 2014-5-26 21:46:43
kan kan
Mikel
发表于 2014-6-18 20:48:45
淡定,淡定,淡定……
Mikel
发表于 2014-6-18 20:50:09
甲鱼哥, 你演示的那个旋转的三角形如何做出来的,我想试试自己能不能做出来送女朋友:loveliness::loveliness::loveliness:
Mikel
发表于 2014-6-19 08:33:08
淡定,淡定,淡定……
Angel丶L
发表于 2014-7-10 23:34:14
强烈支持楼主ing……
牡丹花下死做鬼
发表于 2014-7-10 23:38:35
强烈支持楼主ing……
黑色
发表于 2014-7-14 22:52:40
真是难得给力的帖子啊。
我要成为海贼王
发表于 2014-7-23 20:23:05
新手。楼主加油,鱼C加油!我们都看好你哦!
shappyds1
发表于 2014-8-11 19:57:24
先回复看看
zqqqqz2000
发表于 2014-8-12 17:45:53
强烈支持楼主ing……