datasheet
超过460,000+ 应用技术资源下载
null

链表的源代码

  • 1星
  • 日期: 2015-05-16
  • 大小: 1.75KB
  • 所需积分:1分
  • 下载次数:0
  • favicon收藏
  • rep举报
  • 分享
  • free评论
标签: 链表的实现

链表的实现源代码,包括链表的插入删除修改等

#include #include typedef struct node { int item; struct node *next; }node; node *head = NULL; node *mk_node(int item) { node *p = (node *)malloc(sizeof(node)); if(p == NULL) { printf("malloc fail"); } p -> item = item; p -> next = NULL; return p; } void insert_node(node *p) { p -> next = head; head = p; } void traverse() { node *p = head; while(p != NULL) { printf("%d ",p -> item); p = p -> next; } printf("\n"); } node *find_item(int item) { node *p = head; while(p != NULL) { if(p -> item == item) { return p; } p = p -> next; } return NULL; } void delete_node(node *p) { node *pre = head; if(pre == p) { head = head -> next; } while(pre != NULL) { if(pre -> next == p) { pre -> next = p -> next; } pre = pre -> next; } } void free_node(node *p) { free(p); } void destory() { node *p; while(head != NULL) { p = head; head = head -> next; free_node(p); } } void reverse() { node *nhead = NULL; node *p; while(head != NULL) { p = head; head = head -> next; p -> next = nhead; nhead = p; } head = nhead; } main() { node *p = mk_node(1); insert_node(p); traverse(); p = mk_node(2); insert_node(p); traverse(); p = mk_node(3); insert_node(p); reverse(); traverse(); p = find_item(1); if(p != NULL) { printf("find %d\n",p -> item); }else { printf("not find"); } delete_node(p); free_node(p); traverse(); destory(); traverse(); }
更多简介内容

评论

下载专区


TI最新应用解决方案

工业电子 汽车电子

$(function(){ var appid = $(".select li a").data("channel"); $(".select li a").click(function(){ var appid = $(this).data("channel"); $('.select dt').html($(this).html()); $('#channel').val(appid); }) })