题目1181:遍历链表
来源:互联网 发布:c4d全局光照优化设置 编辑:程序博客网 时间:2024/05/20 23:34
Problem:
Solution:
题目要求很清楚,先建立一个链表,再对链表进行类似于冒泡的排序即可
#include <iostream>#include <stdlib.h>#include <stdio.h>using namespace std;struct LNode{ int val; struct LNode *next;};int main(){ int n,m; LNode *head,*p,*q; while (cin >> n) { head = (LNode*)malloc(sizeof(LNode)); head -> next = NULL; q = head; if (n == 0) cout<<endl; else { for (int i = 0;i < n;i++) { cin >> m; p = (LNode*)malloc(sizeof(LNode)); p -> val = m; q -> next = p; q = q -> next; } p -> next = NULL; } p = head->next; while(p!=NULL){ q=p->next; while(q!=NULL){ if(p->val>q->val){ int temp=p->val; p->val=q->val; q->val=temp; } q=q->next; } p=p->next; } while (head->next) { cout <<head->next->val<< " " ; head = head->next; } } free(head); free(p); free(q); return 0;}
0 0
- 题目1181:遍历链表
- 题目1181:遍历链表
- 题目1181:遍历链表
- 题目1181:遍历链表
- 题目1181:遍历链表
- 题目1181:遍历链表
- 题目1181:遍历链表
- 【九度】题目1181:遍历链表
- 九度OJ 题目1181:遍历链表
- 九度OJ 题目1181:遍历链表
- 【九度OJ】题目1181:遍历链表 解题报告
- 数据结构题目,后续遍历
- (题目32)题目1078:二叉树遍历
- 题目32:二叉树遍历
- 题目1184:二叉树遍历
- 题目1084: 二叉树遍历
- 题目1:二叉树遍历
- 题目1078:二叉树遍历
- 事务TransactionStatus的RollbackOnly属性的作用
- 数据库设计经验谈
- linux socket编程 出现信号SIGPIPE,分析及解决
- ros下分布式的调试和节点
- Android Intent隐式调用之intent-filter匹配规则
- 题目1181:遍历链表
- Linux命令中su与sudo的详细区别
- zhgl 错误 其他信息: “Oracle.DataAccess.Client.OracleConnection”的类型初始值设定项引发异常。
- Excel macro note
- Vue-cli是何物?创建项目脚手架
- Failed to read candidate component class
- 什么是servlet入门级别和大拿?
- HTTP状态码之200和304
- 1072. Gas Station (30) PAT 甲级