青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

牽著老婆滿街逛

嚴以律己,寬以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

TAILQ Example

from:http://unx.ca/log/2006/08/19/tailq-example/

I plan to use this blog to post codebits that I find myself sending to people over and over again. The first example is how to use a TAILQ from sys/queue.h found on the BSDs. Many Linux distributions also have sys/queue.h but may be missing certain macros such as TAILQ_FOREACH(). At the very least I hope this enticies some newer C programmer to use queue.h rather than rolling their own linked list. I’ll jump directly to the code as I feel it is more or less self explanatory.

The following code can be downloaded here.

/*
 * TAILQ example program.
 */
#include <stdlib.h>
#include <stdio.h>
/*
 * On many OpenBSD/NetBSD/FreeBSD you could include <sys/queue.h>, but
 * for portability we’ll include the local copy.
 */
#include "queue.h"
/*
 * This structure defines each item in our tail queue.  It must also
 * contain an item (TAILQ_ENTRY) that points to the next and previous
 * items in the tail queue.
 *
 * For simplicity, we will be creating a list of integers.
 */
struct tailq_entry {
int value;
/*
         * This holds the pointers to the next and previous entries in
         * the tail queue.
         */
TAILQ_ENTRY(tailq_entry) entries;
};
/*
 * Our tail queue requires a head, this is defined using the
 * TAILQ_HEAD macro.
 */
TAILQ_HEAD(, tailq_entry) my_tailq_head;
int
main(int argc, char **argv)
{
/* Define a pointer to an item in the tail queue. */
struct tailq_entry *item;
/* In some cases we have to track a temporary item. */
struct tailq_entry *tmp_item;
int i;
/* Initialize the tail queue. */
TAILQ_INIT(&my_tailq_head);
/* Add 10 items to the tailq queue. */
for (i = 0; i < 10; i++) {
/*
                 * Each item we want to add to the tail queue must be
                 * allocated.
                 */
item = malloc(sizeof(*item));
if (item == NULL) {
perror("malloc failed");
exit(EXIT_FAILURE);
}
/* Set the value. */
item->value = i;
/*
                 * Add our item to the end of tail queue. The first
                 * argument is a pointer to the head of our tail
                 * queue, the second is the item we want to add, and
                 * the third argument is the name of the struct
                 * variable that points to the next and previous items
                 * in the tail queue.
                 */
TAILQ_INSERT_TAIL(&my_tailq_head, item, entries);
}
/* Traverse the tail queue forward. */
printf("Forward traversal: ");
TAILQ_FOREACH(item, &my_tailq_head, entries) {
printf("%d ", item->value);
}
printf("n");
/* Insert a new item after the item with value 5. */
printf("Adding new item after 5: ");
TAILQ_FOREACH(item, &my_tailq_head, entries) {
if (item->value == 5) {
struct tailq_entry *new_item =
malloc(sizeof(*new_item));
if (new_item == NULL) {
perror("malloc failed");
exit(EXIT_FAILURE);
}
new_item->value = 10;
TAILQ_INSERT_AFTER(&my_tailq_head, item, new_item,
entries);
break;
}
}
/* Do another forward traversal to show the newly added item. */
TAILQ_FOREACH(item, &my_tailq_head, entries) {
printf("%d ", item->value);
}
printf("n");
/*
         * Delete the item with the value 3.
         *
         * We can’t use TAILQ_FOREACH here as TAILQ_FOREACH is not
         * safe against deletions during the traversal.  Some variants
         * of queue.h have TAILQ_FOREACH_MUTABLE or TAILQ_FOREACH_SAFE
         * which are safe against deletions.
         */
printf("Deleting item with value 3: ");
for (item = TAILQ_FIRST(&my_tailq_head); item != NULL; item = tmp_item)
{
tmp_item = TAILQ_NEXT(item, entries);
if (item->value == 3) {
/* Remove the item from the tail queue. */
TAILQ_REMOVE(&my_tailq_head, item, entries);
/* Free the item as we don’t need it anymore. */
free(item);
break;
}
}
/* Another forward traversal to show that the value 3 is now gone. */
TAILQ_FOREACH(item, &my_tailq_head, entries) {
printf("%d ", item->value);
}
printf("n");
/* Free the entire tail queue. */
while (item = TAILQ_FIRST(&my_tailq_head)) {
TAILQ_REMOVE(&my_tailq_head, item, entries);
free(item);
}
/* The tail queue should now be empty. */
if (!TAILQ_EMPTY(&my_tailq_head))
printf("tail queue is NOT empty!n");
return 0;
}

posted on 2007-08-21 01:45 楊粼波 閱讀(1245) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美日韩国产综合在线| 欧美大尺度在线观看| 欧美日韩一区视频| 亚洲欧洲在线一区| 欧美福利网址| 欧美1区2区3区| 999亚洲国产精| 欧美激情精品久久久久久免费印度 | 国产精品一区二区视频| 一区二区三区四区国产| 99ri日韩精品视频| 欧美三级欧美一级| 欧美在线观看视频在线| 久久se精品一区二区| 一区在线观看| 麻豆精品在线播放| 免费久久99精品国产自在现线| 亚洲国产精品久久91精品| 久久免费高清视频| 美女黄毛**国产精品啪啪| 亚洲精品中文字幕女同| 亚洲欧洲一二三| 欧美v日韩v国产v| 亚洲午夜三级在线| 午夜日韩视频| 亚洲精品乱码久久久久久| 亚洲九九爱视频| 国产一区二区三区免费不卡 | 亚洲国产裸拍裸体视频在线观看乱了| 欧美激情中文字幕乱码免费| 欧美日韩免费观看一区二区三区| 欧美一级大片在线免费观看| 久久久免费av| 亚洲图片在线| 久热精品在线| 午夜在线观看免费一区| 免费看亚洲片| 久久精彩免费视频| 欧美激情一区二区三区在线视频观看| 亚洲欧美日韩精品久久奇米色影视| 久久九九免费| 亚洲综合社区| 媚黑女一区二区| 亚欧成人在线| 欧美国产在线观看| 久久亚洲综合网| 国产精品午夜国产小视频| 亚洲国产小视频在线观看| 国产日韩成人精品| 亚洲国产精品va| 狠狠色综合网| 亚洲欧美久久久久一区二区三区| 亚洲日本电影| 久久夜色精品国产亚洲aⅴ| 亚洲欧美日韩视频一区| 欧美激情精品久久久久久变态 | 亚洲欧洲偷拍精品| 欧美诱惑福利视频| 午夜欧美精品| 欧美日韩国语| 亚洲精品系列| 亚洲毛片在线| 欧美韩日一区二区三区| 欧美/亚洲一区| 一色屋精品视频在线看| 校园激情久久| 亚洲字幕一区二区| 欧美三级欧美一级| 一区二区三区视频在线| 99视频+国产日韩欧美| 蜜臀久久99精品久久久久久9| 老司机一区二区| 狠狠爱成人网| 久久综合网色—综合色88| 久久久久久亚洲精品中文字幕| 国产精品久久久久久久免费软件 | 亚洲精品美女在线| 99re在线精品| 欧美日韩一区二区三区视频| 亚洲日本欧美日韩高观看| 亚洲精品亚洲人成人网| 欧美人在线观看| 日韩一区二区精品| 亚洲欧美怡红院| 国模精品一区二区三区色天香| 欧美在线观看一二区| 免费的成人av| 99人久久精品视频最新地址| 欧美精品日韩综合在线| av成人免费在线| 欧美一区二区三区男人的天堂 | 国产一区二区三区在线观看网站| 亚洲欧美国产精品专区久久| 久久久久免费| 亚洲国产另类久久久精品极度| 欧美jizzhd精品欧美喷水| 亚洲欧洲综合| 欧美一区二区黄| 亚洲电影成人| 欧美色图天堂网| 久久国产精品一区二区三区四区| 欧美激情在线| 亚洲素人在线| 国产视频不卡| 欧美精品一线| 欧美在线中文字幕| 亚洲精品欧美激情| 久久成人18免费观看| 亚洲三级视频| 国产麻豆成人精品| 欧美xxxx在线观看| 久久av资源网站| 亚洲精品综合在线| 久久精品国产99国产精品| 亚洲经典自拍| 国产亚洲欧美另类中文| 欧美欧美全黄| 久久久福利视频| 亚洲天堂网在线观看| 欧美成人午夜激情在线| 亚洲欧美日韩一区二区| 亚洲精品久久久久久久久| 国产精品永久| 欧美日韩在线观看一区二区三区| 久久久999精品视频| 在线亚洲精品| 亚洲欧洲一区二区天堂久久 | 久久精品系列| 亚洲午夜国产一区99re久久| 亚洲国产精品激情在线观看| 国产裸体写真av一区二区| 欧美日韩国产区| 你懂的视频欧美| 久久成人免费电影| 亚洲天堂成人在线视频| 日韩视频中午一区| 欧美顶级艳妇交换群宴| 久久精品99无色码中文字幕| 亚洲专区在线视频| 亚洲一区二区免费在线| 日韩视频免费观看高清在线视频| 在线观看91精品国产入口| 国产视频在线一区二区 | 亚洲综合国产激情另类一区| 欧美黄色一区| 欧美国产日韩xxxxx| 久色成人在线| 免费欧美日韩| 欧美**字幕| 久久手机免费观看| 久久精品国亚洲| 久久国产直播| 久久精品九九| 麻豆9191精品国产| 久久精品亚洲一区| 欧美一区二区日韩| 亚洲欧美美女| 欧美专区在线观看一区| 久久九九精品| 麻豆乱码国产一区二区三区| 免费视频一区二区三区在线观看| 欧美不卡视频一区发布| 欧美激情第一页xxx| 91久久精品美女| 一本久久综合| 欧美怡红院视频一区二区三区| 久久激情五月婷婷| 欧美aaa级| 欧美日韩国语| 国产一级久久| 在线播放中文一区| 亚洲精品一区二区三| 在线视频精品| 欧美一区二区三区在线| 久久亚洲私人国产精品va| 欧美福利电影在线观看| 99国产精品久久| 亚洲午夜久久久久久久久电影网| 午夜精品国产精品大乳美女| 久久久久久久久综合| 欧美人体xx| 国产偷久久久精品专区| 亚洲人成在线播放网站岛国| 亚洲午夜久久久久久久久电影网| 久久精品中文| 亚洲乱码国产乱码精品精可以看| 亚洲影院污污.| 久久综合色播五月| 欧美色欧美亚洲高清在线视频| 国产精品卡一卡二卡三| 亚洲福利国产| 午夜精品久久久久久久久久久久久| 久久久久九九九九| 亚洲精品中文在线| 午夜视频在线观看一区二区| 欧美成人国产一区二区| 国产午夜精品在线| 一区二区三区黄色| 米奇777超碰欧美日韩亚洲| 一区二区三区精品|