• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

C语言使用utlist实现的双向链表

c语言 搞代码 4年前 (2022-01-09) 64次浏览 已收录 0个评论
#include #include #include #include "utlist.h"  #define BUFLEN 20  typedef struct el {    char bname[BUFLEN];    struct el *next, *prev;} el;  int namecm<strong>本文来源gaodai#ma#com搞@@代~&码网</strong>p(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;}

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:C语言使用utlist实现的双向链表
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址