设为首页 加入收藏

TOP

C实现通用数据结构--单链表(三)
2014-11-23 19:22:16 来源: 作者: 【 】 浏览:30
Tags:实现 通用 数据结构 单链表
}
print_list(&list); //打印初始list
element = list_head(&list); //指向头结点
for (i = 0; i < 7; i++)
element = list_next(element);
data = list_data(element);
fprintf(stdout, "Removing an element after the one containing %03d\n", *data);
if (list_rem_next(&list, element, (void **)&data) != 0) //删除指定结点
return 1;
print_list(&list);
fprintf(stdout, "Inserting 011 at the tail of the list\n");
*data = 11;
if (list_ins_next(&list, list_tail(&list), data) != 0) //插入指定结点
return 1;
print_list(&list);
fprintf(stdout, "Removing an element after the first element\n");
element = list_head(&list);
if (list_rem_next(&list, element, (void **)&data) != 0)
return 1;
print_list(&list);
fprintf(stdout, "Inserting 012 at the head of the list\n");
*data = 12;
if (list_ins_next(&list, NULL, data) != 0)
return 1;
print_list(&list);
fprintf(stdout, "Iterating and removing the fourth element\n");
element = list_head(&list);
element = list_next(element);
element = list_next(element);
if (list_rem_next(&list, element, (void **)&data) != 0)
return 1;
print_list(&list);
fprintf(stdout, "Inserting 013 after the first element\n");
*data = 13;
if (list_ins_next(&list, list_head(&list), data) != 0)
return 1;
print_list(&list);
i = list_is_head(&list, list_head(&list));
fprintf(stdout, "Testing list_is_head...Value=%d (1=OK)\n", i);
i = list_is_head(&list, list_tail(&list));
fprintf(stdout, "Testing list_is_head...Value=%d (0=OK)\n", i);
i = list_is_tail(list_tail(&list));
fprintf(stdout, "Testing list_is_tail...Value=%d (1=OK)\n", i);
i = list_is_tail(list_head(&list));
fprintf(stdout, "Testing list_is_tail...Value=%d (0=OK)\n", i);
fprintf(stdout, "Destroying the list\n");
list_destroy(&list);
return 0;
}
首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Swift和Objective-C混合编程 下一篇c语言const关键字

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: