ผลต่างระหว่างรุ่นของ "Algo lab/templates/icecream1"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
(Jittat ย้ายหน้า Algo lab/icecream1 templates ไปยัง Algo lab/templates/icecream1)
 
แถว 2: แถว 2:
 
#include <iostream>
 
#include <iostream>
 
using namespace std;
 
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 main()

รุ่นแก้ไขปัจจุบันเมื่อ 02:22, 26 สิงหาคม 2567

#include <iostream>
using namespace std;

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...
  
}