在经历过上千次的笔试中,反复做同样的试题;不胜其烦,不过没办法为了更好的生活还得做!对于链表的实现做为一名C开发工程师那是一定要憝知的。就算不理解也得死记下来。不然就别去好点的公司面试吧,劝告还是回家苦学一下再去试试运气,言归正传吧!让我们理解加记忆一字不差的拷贝的大脑里去,得高分才有机会拿高薪哦!哈哈,有动力了吧!我们现在开始吧:
1。单链表的建立
完整代码如下:
#include<iostream> #include<stdio.h> #include<string.h> #include<conio.h> using namespace std;
typedef struct student { int data; struct student *next; }node;
node *creat() { node *head ,*p,*s; int x,cycle=1; head =(node*)malloc(sizeof(node)); p = head; while(cycle) { printf("\nplease input the data:"); scanf("%d",&x); if(x!=0) { s=(node*)malloc(sizeof(node)); s->data=x; printf("\n %d",s->data); p->next = s; p = s; } else cycle = 0; } head = head->next; p->next = NULL; printf("\n yyy %d",head->data); return (head); }
|
2.单链表的测长
代码如下:
int length(node *head) { int n = 0; node *p; p = head; while(p != NULL) { p = p->next; n++; } return(n); }
|
3.单链表的打印
代码如下:
void print(node *head) { node *p; int n; n = length(head); printf("\n Now,These %d record are:\n",n); p = head; if(head != NULL) while(p != NULL) { printf("\n uuu %d ",p->data); p = p->next; } }
|
现在发现自己打blog太累了!有点晚了!下班回家了。明天接着写!
阅读(934) | 评论(0) | 转发(0) |