循环队列(FIFO)
const int SIZE = 10;
int info[SIZE], head = 0, tail = 0;
inline bool empty() {
return (head == tail);
}
inline int size() {
return (tail - head + SIZE) % SIZE;
}
inline int front() {
return info[(head + 1) % SIZE];
}
inline int back() {
return info[tail];
}
inline void push_back(int ins) {
tail = (tail + 1) % SIZE;
info[tail] = ins;
}
inline void pop_front() {
head = (head + 1) % SIZE;
}
栈(LIFO)
#include<iostream>
using namespace std;
const int SIZE = 100;
int info[SIZE], tail = 0;
inline bool empty(){
return !tail;
}
inline int size(){
return tail;
}
inline int top(){
return info[tail];
}
inline void push(int ind){
info[++tail] = ind;
}
inline void pop(){
tail--;
}