連結リスト
ポインタ難しいけどこの際listぐらいは実装できるようになろうと思ったら簡単だった(小並)
こんな感じでいいのかな?
#include <cstdio> #include <cstdlib> using namespace std; struct Node{ Node *prev, *next; int val; }; Node *head, *tail; void init(){ head = tail = NULL; } void make_node(int x){ Node *cur = new Node; cur->val = x; cur->next = NULL; if(tail == NULL){ head = tail = cur; cur->prev = NULL; }else{ tail->next = cur; cur->prev = tail; tail = cur; } } void dest(){ for(Node *now = head; now != NULL;){ Node *rem = now; now = now->next; delete rem; } } int calc_sum(){ int s = 0; for(Node *now = head; now != NULL; now = now->next) s += now->val; return s; }