严蔚敏版数据结构算法2.2
来源:互联网 发布:小金猪装饰预算软件 编辑:程序博客网 时间:2024/05/06 20:31
#include <iostream>#include<vector>using namespace std;typedef int element;#define maxsize 100typedef struct { element aa[maxsize]; int last;}sqlist;void merglist(sqlist *la, sqlist * lb, sqlist *lc) { int i = 0, j = 0, k = 0; while ((i <= la->last) && (j <= lb->last)) { if (la->aa[i] <= lb->aa[j]) { lc->aa[k] = la->aa[i]; i++; k++; } else { lc->aa[k] = lb->aa[j]; j++; k++; } } while (i<=la->last) { lc->aa[k] = la->aa[i]; i++; k++; } while (j<=lb->last) { lc->aa[k] = lb->aa[j]; i++; k++; } lc->last = la->last + lb->last + 1;}int main(){ int len, i; sqlist *la, *lb, *lc; la = (sqlist*)malloc(sizeof(sqlist)); cout << "输入链表a的长度:" << endl; cin >> len; la->last = len - 1; cout << "输入元素:" << endl; for (i = 0; i < len; i++) cin >> la->aa[i]; lb = (sqlist*)malloc(sizeof(sqlist)); cout << "输入链表b的长度:" << endl; cin >> len; lb->last = len - 1; cout << "输入元素:" << endl; for (i = 0; i < len; i++) cin >> lb->aa[i]; lc = (sqlist*)malloc(sizeof(sqlist)); merglist(la, lb, lc); for (i = 0; lc->last < len; i++) cout << lc->aa[i] << " "; cout << endl; return 0; }
0 0
- 严蔚敏版数据结构算法2.2
- 数据结构C语言版算法2.2
- 严蔚敏版数据结构课本代码——算法2.2
- 严蔚敏版数据结构课本代码——算法2.2
- 数据结构&算法
- 数据结构算法
- 数据结构算法
- 数据结构算法
- 数据结构算法
- 数据结构算法
- 数据结构算法
- 数据结构算法
- 数据结构 算法
- 数据结构-算法
- 数据结构算法
- 数据结构-算法
- 数据结构+算法
- 数据结构&算法
- 不要被语言本身所束缚
- 如何配置 reactnative 在 win7
- jquery取某id的值
- iOS文件目录结构
- leetcode 350---Intersection of Two Arrays II 数组 双指针 排序
- 严蔚敏版数据结构算法2.2
- Hibernate总结--------缓存
- 软件如何控制硬件、编译器和操作系统是否需要编译
- Cracking the Code Interview Chapter Two-- TaylorZhangYuxin's Solusion
- Adnroid源码学习笔记:Handler 线程间通讯
- 使用JavaScriptCore在JS和OC间通信
- maven常用插件用法
- 梯度下降法和随机梯度下降法的区别
- IntentService的使用