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

📄 pex4_1.cpp

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

typedef int DataType;

#include "aseqlist.h"

// traverse list L and print each element
void PrintList(SeqList L)
{
	// access each element by its position using GetData
	for(int i=0;i < L.ListSize();i++)
		cout << L.GetData(i) << "  ";
	cout << endl;
}

// insert elt into list L only if it is larger than
// all existing data values in L
void InsertMax(SeqList& L, int elt)
{
	// assume elt will be larger than all values in L
	int larger = 1;
	
	// traverse L and compare each element to elt
	for(int i=0;i < L.ListSize();i++)
		// if elt is smaller or equal to a list value, assign
		// larger to FALSE and break out of the for
		if (elt <= L.GetData(i))
		{
			larger = 0;
			break;
		}
		
	// if elt is larger than all existing list elements,
	// insert it in L
	if (larger)
		L.Insert(elt);
}

void main(void)
{
	SeqList L;
	int value;
	
	cout << "Enter 10 integer values: ";
	for(int i=0;i < 10;i++)
	{
		cin >> value;
		InsertMax(L,value);
	}

	PrintList(L);
}

/*
<Run>

Enter 10 integer values: 1 5 3 12 7 9 10 11 15 55
1  5  12  15  55
*/

⌨️ 快捷键说明

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