码迷,mamicode.com
首页 > 其他好文 > 详细

链表模板!

时间:2014-10-09 02:18:57      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

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

 

链表模板!

标签:style   blog   http   color   io   os   ar   for   sp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!