COMMENTS

自写一则单链表小程序

发现很多公司面试都喜欢考链表,实际项目中尽管需要自己写链表的时候比较少,但还是会经常用到,链表是一种常用的数据结构。有必要整理一下自己的思路,索性写了一个。包括了链表的初始化,插入,删除,查找,销毁,打印等基本功能,当然考虑了头尾中间等位置情况。仓促完成的简单代码,bug比较多,链表中只存储了一个整形的变量,没有做数据类型的判断,有时候会段错误也难免。已知的一个问题就是创建的链表在有销毁前如果再创建一个的话,会造成内存泄露,因为之前的链表没有销毁头指针便指向了新的位置,旧链表就永远找不到哦。这些问题留在以后实际用到的时候再考虑吧,应付面试这个足矣!

?Download node.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <stdio.h>
#include <stdlib.h>
typedef struct node_t {
	int value;
	struct node_t *next;
} node;
#define LENGTH sizeof(node)
 
node *init_node(){
  int node_length,n=0;
  node *head=NULL;
  node *node_temp1,*node_temp2;
  node_temp2=(node *)malloc(LENGTH);
  printf("node length want to create:");
  scanf("%d",&node_length);
  if(node_length<1){
    printf("no node to create!");
    exit(0);
  }
  while(n<node_length){
    node_temp1=(node *)malloc(LENGTH);
 
    printf("input NO.%d value:",n+1);
    scanf("%d",&node_temp1->value);
    node_temp1->next=NULL;
    if(n==0)
      head=node_temp1;
    else
      node_temp2->next=node_temp1;
    node_temp2=node_temp1;
    n++;
  }
  return head;
}
 
node *insert_node(node *head){
  int insert_value;
  node *temp_node1=head;
  node *temp_node2=(node *)malloc(LENGTH);
  node *temp_node3=NULL;
  printf("insert value:");
  scanf("%d",&insert_value);
  while(temp_node1!=NULL){
    if(temp_node1->value<insert_value){
      temp_node3=temp_node1;
      temp_node1=temp_node1->next;
    }
    else
      break;
  }
  temp_node2->value=insert_value;
  if(temp_node3==NULL){/*locate the first node*/
    temp_node3=head;
    temp_node2->next=temp_node3;
    head=temp_node2;
  }
  else if(temp_node1!=NULL){  /*locate the medium of head,insert between temp3 and temp1*/    
    temp_node2->next=temp_node3->next;
    temp_node3->next=temp_node2;
  }else{  /*locate the end of head*/
    temp_node2->next=NULL;
    temp_node3->next=temp_node2;
  }
  return head;
}
 
node *delete_node(node *head){
  int del_value;
  node *temp_node1=head;
  node *temp_node2;
  printf("input the delete value:");
  scanf("%d",&del_value);
  if(head->value==del_value){ /* delete the head of node*/
    temp_node2=head;
    head=head->next;
    return head;
  }
 
  while(temp_node1!=NULL){
    if(temp_node1->value!=del_value){
      temp_node2=temp_node1;
      temp_node1=temp_node1->next;
    }
    else
      break;
  }
  if(temp_node1!=NULL){
    temp_node2->next=temp_node1->next;
    free(temp_node1);
  }else
    printf("not find what you want to delete!\n");
  return head;
}
 
void search_node(node *head){
  int search_value,n=1;
  node *temp_node=head;
  printf("insert the value which you find:");
  scanf("%d",&search_value);
  while(temp_node!=NULL){
    if(temp_node->value!=search_value){
      temp_node=temp_node->next;
      n++;
    }
    else
      break;
  }
  if(temp_node!=NULL)
    printf("finded what you want.\nthe %d node`s value:%d\n",n,temp_node->value);
  else
    printf("not find!\n");
}
 
void print_node(node *head){
  if(head==NULL){
    printf("blank node!create first please!\n");
    return;
  }
  node *temp_node=head; 
  do{
    printf("value:%d\n",temp_node->value);
    temp_node=temp_node->next;
  } while(temp_node!=NULL);
}
 
node *destroy_node(node *head){
  if(head==NULL){
    printf("blank node!create first please!\n");
    return;
  }
  node *temp_node;
  do{
    temp_node=head->next;
    free(head);
    head=temp_node;
  }while(head!=NULL);
  return head;
}
 
int main(){
  int options;
  node *head=NULL;
loop:
  printf("select options:\t1:create 2:insert 3:delete 4:find 5:print 6:destory 7:exit\ninput options:");
  scanf("%d",&options);
  switch(options){
    case 1:
      head=init_node();
      break;
    case 2:
      head=insert_node(head);
      break;
    case 3:
      head=delete_node(head);
      break;
    case 4:
      search_node(head);
      break;
    case 5:
      print_node(head);
      break;
    case 6:
      head=destroy_node(head);
      break;
    case 7:
      printf("byebye!");
      return 0;
    default:
      printf("invalid options!");
  }
  goto loop;
}

那点简历---越活越真实

如果上次的更换工作不算跳槽的话,这次的得算了。
简历改了一遍又一遍,拿着改满意的简历再和刚毕业那会的对比,发现了很多的不同。
主修过N多的课程统统的删掉了,因为发现很多名字都已经有些生疏了;带熟悉字眼的也统统干掉了,其实自己什么都不懂,难道会写个hello就说英语牛X了;精通的字眼大都改成了熟悉、了解,真佩服自己当年的肺活量,太能吹了;实话实说的写了一段自己做过什么,这才是最真实的一段了。
进了这个圈才知道,自己能圈住的原来寥寥无几。随着慢慢的圈住一些东西,才懂得自己应该圈住哪些,外面的世界太大了,抓住适合自己的,真正为我所用的才是关键。
虽说简历要展现自己,做的多么华丽,写的多么坚决,但现在看起来,这些指导让我颇有些心虚,为难。
拿着这份简历面试了一下午,这都是好几周前的事了。现在敢写出来也是因为已经不属于那里,也就不用怎么顾忌。其实人家看的也就是自己觉得最真实的那段。聊的很多东西都是关于具体的项目,职业的规划。看来刚毕业的一大段只能归结为凑字数。
曾经就听到之前的经理闲谈之间说到,凡是说精通的,顶多算个了解,说了解的,大概也就知道个名字。真是悲哀,大家心知肚明,却也只能这样。
真实过后,等我再去吹嘘的时候,应该能吹一个更大,大好几倍的泡泡,想想都觉得刺激。继续努力,鼓励自己了!

今天离职了

刚刚办完了离职手续,再有一会就离开这里了
一年多的时光,接触到了很多领域,还是非常感谢公司对我的培养!
祝愿公司日益强大,越来越好!
朝着自己的方向,继续前进了!