青岛做网站的大公司有,三河市建设局网站,网站群建设论文,ps怎么做网站首页模板类就是将类定义成模板的形式。
C中好像不区分内部类与嵌套类两个名词。
内部类与嵌套类都是指在类中定义类。
局部类是指在函数中定义类。
#xff08;c不能在函数中定义函数(python可以)。c在类中定义的函数也就是成员函数。#xff09; #xff08;c内部类与java内…模板类就是将类定义成模板的形式。
C中好像不区分内部类与嵌套类两个名词。
内部类与嵌套类都是指在类中定义类。
局部类是指在函数中定义类。
c不能在函数中定义函数(python可以)。c在类中定义的函数也就是成员函数。 c内部类与java内部类最大的区别就是c的内部类对象没有外部类对象的指针不能访问外部类对象的非静态成员java的非静态内部类对象有外部类对象的指针能访问外部类对象的非静态成员。 java 中右多个内部类还有匿名内部类。 通过嵌套类定义自己的队列Queue
Queue类里面嵌套一个Node类
编写Queue.h文件
#ifndef QUEUE_H_#define QUEUE_H_templateclass Type
class Queue{
private:enum {Q_SIZE 10};class Node{public:Type data;Node * next;Node(const Type data) : data(data), next(0) {}}; Node *front;Node *rear;int curSize;int maxSize;
public:Queue(int size Q_SIZE);~Queue();bool isFull() const;bool isEmpty() const ;bool enQueue(const Type data);bool deQueue();void tarverseQueue() const;
};#endif 编写Queue.cpp文件
#include iostream
#include string
#include cstring
#include cstdlib
#include valarray
#include Queue.h
using std::cout;
using std::endl;templateclass Type
QueueType::Queue(int size) : maxSize(size) {front rear 0;curSize 0;
}templateclass Type
QueueType::~Queue() {Node *tmp;while (front ! 0) {tmp front;front front-next;delete tmp;}
}templateclass Type
bool QueueType::isFull() const {return curSize maxSize;
}templateclass Type
bool QueueType::isEmpty() const {return curSize 0;
}templateclass Type
bool QueueType::enQueue(const Type data) {if (isFull()) {return false;} Node *node new Node(data);if (front 0) {front node;} else {rear-next node;} rear node;curSize;return true;
}templateclass Type
bool QueueType::deQueue() {if (isEmpty()) {return false;}Node *tmpNode front;front front-next;delete tmpNode;if (front 0) {rear 0;}curSize--;return true;
}templateclass Type
void QueueType::tarverseQueue() const {Node *head front;while (head ! 0) {cout head-data endl;head head-next;}
}int main(int argc, char *argv[]) {Queueint queue(10);queue.enQueue(11);queue.enQueue(12);queue.tarverseQueue();return 0;
}
参考资料
https://blog.csdn.net/solariens/article/details/52314896
https://blog.csdn.net/lw585625/article/details/84085249