2013年百度实习生面试 编程题之--单链表的反转
来源:互联网 发布:vue.js ide 编辑:程序博客网 时间:2024/06/06 01:37
单链表的反转,虽然想起来容易,但是要实现一个没有错误的可运行代码却没那么简单。代码如下
#include<stdio.h>#include<stdlib.h>typedef struct{int value;struct node_t* next;}node_t;node_t* head;void buildLink(int);void printLink();void buildLink(int n){int i=0;node_t* tmp;node_t* tmpnode;if(n>=1){head = malloc(sizeof(node_t));head->value = rand()%99;tmp = head;for(i=1;i<n;i++){tmpnode = malloc(sizeof(node_t));tmpnode->value = rand()%99;//printf("value of node %d\n",i);//scanf("%d",&tmpnode->value);tmp->next = tmpnode;tmp = tmp->next;}}}void printLink(){int i =0;node_t* first = head;while(first!=NULL){printf("node %d 's value is %d\n ",i,first->value);first=first->next;i++;}}void revirse(){node_t* first = head;node_t* tmp;node_t* afterTmp;if(head==NULL)return;tmp = first->next;if(tmp==NULL)return;afterTmp = tmp->next;while(afterTmp!=NULL){tmp->next = first;first = tmp;tmp = afterTmp;afterTmp = afterTmp->next;}tmp->next = first;head->next =NULL;head = tmp;}int main(void){int i =0;printf("input node number\n");scanf("%d",&i);buildLink(i);printf("before revirse\n");printLink();revirse();printf("after revirse\n");printLink();return 1;}
- 2013年百度实习生面试 编程题之--单链表的反转
- 2017百度春季实习生编程题之有趣的排序
- 2017百度春季实习生编程题之不等式数列
- 我的百度实习生面试(一)
- 2012年百度实习生笔试面试
- 2015年百度测试开发实习生面试
- 百度实习生面试经历
- 百度实习生面试经历
- 百度实习生面试总结
- 百度实习生面试总结
- 面试题目之单链表的反转
- 2014年实习生招聘之百度上海研发中心实习生招聘电话面试—2014/04/18
- 阿里巴巴、百度Android实习生,面试之旅(上)
- 阿里巴巴、百度Android实习生,面试之旅(下)
- 百度前端实习生面试(连跪之旅)
- 百度2017暑期实习生编程题
- 2017百度实习生招聘编程题
- 百度2017暑期实习生编程题
- hdu 1372 Knight Moves (水bfs)
- hdu1071(积分求面积)
- 部落卫队问题
- javascript变量声明有误var的区别
- 实战虚拟化存储设计之LUN Sizing
- 2013年百度实习生面试 编程题之--单链表的反转
- android中的颜色
- UITableView(Inserting and Deleting Rows and Sections)
- 银笺生花,伴你浪迹天涯
- oralce中的undo表空间知识点汇总
- 个人用linux的常用软件和一些问题的解决方案
- MySQL的事务
- 腾讯编程初赛4
- 简易画图板的优化