C 语言经典题目系列解决方案(3)-链表创建与倒置
2010-09-15 09:40
441 查看
题目:链表的创建与倒置。
解决方案:
解决方案:
#define student struct stu #define length sizeof(struct stu) student{ int stuNum; student *next; }; main() { int n,m; student *head,*new,*pCurrent; student *temp,*pFallowed; printf("enter the number of students: "); scanf("%d",&n); m=n; printf("创建链表.........................../n"); while (n>0){ new=(student *)malloc(length); printf("enter the stuNum of students_%d: ",m-n+1); if (n==m) {head=new;pCurrent=new;} else{ pCurrent->next=new; pCurrent=new; } scanf("%d",&(new->stuNum)); n--; } new->next=0; pCurrent=new=0; printf("正向输出链表.........................../n"); pCurrent=head; while(pCurrent){ printf("%d/n",pCurrent->stuNum); pCurrent=pCurrent->next; } printf("倒置链表.........................../n"); pCurrent=head; temp=0; while(pCurrent){ pFallowed=pCurrent->next; pCurrent->next=temp; temp=pCurrent; pCurrent=pFallowed; } head=temp; printf("输出倒置后链表.........................../n"); pCurrent=head; while(pCurrent){ printf("%d/n",pCurrent->stuNum); pCurrent=pCurrent->next; } }
相关文章推荐
- C 语言经典题目系列解决方案(6)-有序链表的归并
- C 语言经典题目系列解决方案(7)-冒泡排序
- C 语言经典题目系列解决方案(8)-选择排序
- C 语言经典题目系列解决方案(11)-折半查找
- C 语言经典题目系列解决方案(1)-报数问题
- C 语言经典题目系列解决方案(5)-gcd问题
- C 语言经典题目系列解决方案(4)-Fibonacci
- C 语言经典题目系列解决方案(9)-直接插入排序
- C 语言经典题目系列解决方案(10)-快排
- C语言经典题目系列解决方案(2)-统计字符
- C 语言的一些经典题目
- <仅是自己做笔记。。。系列x>所有系列题目都来自v_JULY_v前辈的:精选微软等公司经典的算法面试100题
- (省赛训练系列)贪心的说 poj贪心经典题目
- 《WF编程》系列之1 - Hello,Workflow & 创建工作流解决方案
- leetcode题目 反转链表系列问题
- 链表创建 和 倒置
- VSTO之旅系列(二):创建Excel解决方案
- [Jobdu] 题目1511:从尾到头打印链表——单链表的倒置输出
- 网络采集软件核心技术剖析系列(7)---如何使用C#语言搭建程序框架(经典Winform界面,顶部菜单栏,工具栏,左边树形列表,右边多Tab界面)
- VSTO之旅系列(四):创建Word解决方案