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

📄 pex9_7.cpp

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

#include "link.h"

// print LinkedList object L. L is passed
// by value, so the copy constructor is used
template <class T>
void PrintList(LinkedList<T> L)
{
	L.Reset();
	for (int i = 0; i < L.ListSize(); i++)
	{
		cout << L.Data() << "  ";
		L.Next();
	}
	cout << endl;
}		

void main(void)
{
	// declare LinkedList object L
	LinkedList<int> L;
	// values inserted into L
	int A[10] = {4, 7, 1, 3, 9, 0, 2, 8, 5, 6};

	// insert the elements of A at the front of L
	for (int i = 0; i < 10; i++)
		L.InsertRear(A[i]);
		
	// print list L. L is passed by value
	cout << "L: ";
	PrintList(L);
	
	// initialize M with L. the copy constructor is called
	LinkedList<int> M(L);
	
	cout << "M: ";
	PrintList(M);
	
	// declare LinkedList object N
	LinkedList<int> N;
	
	// assignment operator
	N = L;
	cout << "N: ";
	PrintList(N);
}

/*
<Run>

L: 4  7  1  3  9  0  2  8  5  6
M: 4  7  1  3  9  0  2  8  5  6
N: 4  7  1  3  9  0  2  8  5  6
*/

⌨️ 快捷键说明

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