⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pex9_12.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#include <iostream.h>
#pragma hdrstop

#include "wex9_8.h"		// for MergeLists

void main(void)
{
	// create two linked lists list1 and list2
	Node<int> *list1 = NULL, *list2 = NULL, *list3;
	// data values in list1, list2
	int alist1[] = {1,3,4,6,7,10,12,15},
		alist2[] = {3,5,6,8,11,12,14,18,22,33,55};
	
	// create the lists
	for(int i=10;i >= 0;i--)
	{
		if (i <= 7)
			InsertFront(list1,alist1[i]);
		InsertFront(list2,alist2[i]);
	}
	
	// print the lists
	cout << "List 1: ";
	PrintList(list1);
	cout << endl;
	
	cout << "List 2: ";
	PrintList(list2);
	cout << endl;

	// merge list1 and list2 into list3
	MergeLists(list1, list2, list3);
	cout << "Merged list: ";
	PrintList(list3);
	cout << endl;
}

/*
<Run>

List 1: 1  3  4  6  7  10  12  15
List 2: 3  5  6  8  11  12  14  18  22  33  55
Merged list: 1  3  3  4  5  6  6  7  8  10  11  12  12  14  15  18  22  33  55
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -