首页 > 其他 > 详细

链表模板!

时间:2014-10-09 00:39:17      阅读:288      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 
 5 using namespace std;
 6 
 7 struct List
 8 {
 9     int val;
10     List *next;
11 };
12 
13 List *head;
14 
15 void Insert(int k,int val)
16 {
17     List *p,*q;
18     p=head;
19     q=(List *)malloc(sizeof(List));
20     for(int i=0;i<k;i++)
21         p=p->next;
22     q->val=val;
23     q->next=p->next;
24     p->next=q;
25 }
26 
27 void Delete(int k)
28 {
29     List *p,*q;
30     p=head;
31     for(int i=0;i<k-1;i++)
32         p=p->next;
33     q=p->next;
34     p->next=q->next;
35     free(q);
36 
37 }
38 int main()
39 {
40 
41     head=(List *)malloc(sizeof(List));
42     head->next=NULL;
43     return 0;
44 }
View Code

 

链表模板!

原文:http://www.cnblogs.com/M-D-LUFFI/p/4012062.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!