0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CでQueueを使う

Posted at

以前は検索したらすぐ見つかっていたんだけど
最近見つかりにくくなったり、C++のページが引っかかったりしているので

定義

#include <sys/queue.h>
typedef struct str_point {
    TAILQ_ENTRY(str_point) entry;
    int x;
    int y;
} point_t;

typedef struct {
    TAILQ_HEAD(tq_head, str_point) head;
    int count;
} mng_point_t;

// いろいろ面倒なので可能ならglobalに置いた方が楽
mng_point_t manager;

初期化

TAILQ_INIT(&manager.head);

追加

point_t point;
TAILQ_INSERT_TAIL(&manager.head, &point, entry);

削除

TAILQ_REMOVE(&manager.head, &point, entry);

ループ

for (point_t *np = manager.head.tqh_first; np;np = np->entry.tqe_next) {
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?