Algo lab/templates/icecream1
รุ่นแก้ไขเมื่อ 23:38, 22 กันยายน 2564 โดย Jittat (คุย | มีส่วนร่วม) (Jittat ย้ายหน้า Algo lab/icecream1 templates ไปยัง Algo lab/templates/icecream1)
#include <iostream>
using namespace std;
typedef int ValueType;
struct ListNode {
ValueType val;
ListNode* next;
ListNode(ValueType v, ListNode* nxt=0)
: val(v), next(nxt) {}
};
ListNode* front = nullptr;
ListNode* rear = nullptr;
void append(ListNode*& front, ListNode*& rear, ValueType x)
{
ListNode* n = new ListNode(x);
if (rear != nullptr) {
rear->next = n;
rear = n;
} else {
front = rear = n;
}
}
ValueType extract(ListNode*& front, ListNode*& rear)
{
ValueType v = front->val;
ListNode* new_front = front->next;
delete front;
front = new_front;
if (front == nullptr) {
rear = nullptr;
}
return v;
}
int main()
{
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int t;
cin >> t;
if (t == 1) {
int n;
cin >> n;
// your code here
} else {
// here, t = 2. Call someone to the queue.
}
}
// you have to print the number of remaining customers as well.
// iterate the rest of the list here...
}