pex9_12.cpp

来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 45 行

CPP
45
字号
#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 + =
减小字号Ctrl + -
显示快捷键?