中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C語言使用utlist實現(xiàn)的雙向鏈表

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

utlist 下載地址:https://github.com/troydhanson/uthash

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utlist.h"
 
#define BUFLEN 20
 
typedef struct el {
    char bname[BUFLEN];
    struct el *next, *prev;
} el;
 
int namecmp(el *a, el *b) {
    return strcmp(a->bname,b->bname);
}
 
el *head = NULL; /* important- initialize to NULL! */
 
int main(int argc, char *argv[]) {
    el *name, *elt, *tmp, etmp;
 
    char linebuf[BUFLEN];
    int count;
    FILE *file;
 
    if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
        perror("can't open: ");
        exit(-1);
    }
 
    while (fgets(linebuf,BUFLEN,file) != NULL) {
        if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
        strncpy(name->bname,linebuf,BUFLEN);
        DL_APPEND(head, name);
    }
    DL_SORT(head, namecmp);
    DL_FOREACH(head,elt) printf("%s", elt->bname);
    DL_COUNT(head, elt, count);
    printf("%d number of elements in list\n", count);
 
    memcpy(&etmp.bname, "WES\n", 5);
    DL_SEARCH(head,elt,&etmp,namecmp);
    if (elt) printf("found %s\n", elt->bname);
 
    /* now delete each element, use the safe iterator */
    DL_FOREACH_SAFE(head,elt,tmp) {
      DL_DELETE(head,elt);
    }
 
    fclose(file);
 
    return 0;
}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:iOS NSFileManeger 計算文件是否超時,和計算文件夾下文件的總大小

下一篇:Linux下通過C語言操作SqlLite數(shù)據(jù)庫