LinearStack.h
#pragma once template <typename t> class linearqueue//sequence queue {private:int size;
int front;//start position int rear;//end of position T *data;
Public:linearqueue (int size) {this->size = size+1;
This->front = 0;
This->rear = 1;
data = new t[this->size];//dynamic application space, wasting a space to judge whether the team full} ~linearqueue () {delete[] data; } void Creat (T newdata[], int length)//Bulk Create {if (length > Size | | | length <= 0) {throw std::exception ("Le
NGTH error!!!! ");
Return
} this->rear = length;
for (int i = 0; i < length; i++) {data[i] = Newdata[i];
} void EnQueue (T newdata)/join Team tail Operation {if (Isfull ()) {throw std::exception ("over up!!!");
Return
} Data[rear] = NewData;
Rear = (rear + 1)% size;
T dequeue ()//out team head operation {if (IsEmpty ()) {throw std::exception ("Over Bottom!!!");
return NULL;
T temp = Data[front];
Front = (front + 1)% size;
return temp;
BOOL Isfull ()//Determines whether is full {if (rear + 1)% size = = Front) { return true;
return false;
BOOL IsEmpty ()//Determines whether null {if (front + 1)% size = = rear) {return true;
return false;
T GetTop ()//Get team head element {if (IsEmpty ()) {throw std::exception ("Over Bottom!!!");
return NULL;
return data[rear-1];
void Printlist ()//output entire table {int length;
if (Front > rear) {length = rear + Size-front;
cout << "size=" << size-1 << "length=" << length << Endl;
for (int i = front i < size; i++) {cout << data[i] << "";
for (int i = 0; i < rear i++) {cout << data[i] << "";
} else {length = Rear-front;
cout << "size=" << size-1 << "length=" << length << Endl;
for (int i = Front I < rear i++) {cout << data[i] << "";
}} cout << Endl;
cout << Endl; }
};
nodestack.h
#pragma once template <typename t> struct node_queue//node {T data;
Node_queue *next;
}; Template <typename t> class Nodequeue {private:node_queue<t> *front;//team head pointer node_queue<t> *rear;//team tail finger
Pin int length;//length public:nodequeue () {node_queue<t> *n = new node_queue<t>;
N->next = NULL;
Front = rear = n;
length = 0;
} ~nodequeue () {node_queue<t> *temp;
while (Front->next->next!= NULL) {temp = front->next;
Delete front;
Front = temp; } void creat (T *newdata,int length)//batch creation, multiple calls to the queue method {for (int i = 0; i < length; i++) {EnQueue (Newdata[i])
;
} void EnQueue (T newdata)/join Team {node_queue<t> *temp = new node_queue<t>;
Temp->data = NewData;
Temp->next = NULL;
Rear->next = temp;
Rear = temp;
length++;
} T Dequeue ()//out Team {if (Front->next->next = NULL) {throw std::exception ("Over Bottom!!!");
return NULL; } node_queue<t> *temp = front->next;
Front->next = temp->next;
length--;
T t = temp->data;
Delete temp;
return t;
T GetTop ()//get stack top element {if (IsEmpty ()) {throw std::exception ("Over Bottom!!!");
return NULL;
Return front->next->data;
BOOL IsEmpty ()//Determines whether null {if (Front->next = = rear) {return true;
return false;
} void Printlist ()//output {node_queue<t> *temp=front->next;
cout << "size=" << length << Endl;
while (temp!= NULL) {cout << temp->data << "";
temp = temp->next;
} cout << Endl;
cout << Endl; }
}; The queue is characterized by an insert operation at one end and an output operation on the other, so the team head and tail are represented by two int values (or pointers).