pex9_11.cpp

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

CPP
54
字号
#include <iostream.h>
#pragma hdrstop

#include "node.h"
#include "nodelib.h"
#include "wex9_11.h"
#include "wex9_12.h"
			
void main(void)
{
	// create ordered linked list L
	Node<int> *L = NULL;
	// data values in L
	int list[] = {7,5,7,7,8,3,7,35,15,7}, key, count;
	
	// create the list
	for(int i=0;i < 10;i++)
		InsertOrder(L,list[i]);
	
	// print the original list
	cout << "List L: ";
	PrintList(L);
	cout << endl;

	// prompt the user for a key and use CountKey to
	// determine how many times the key occurs in the list
	cout << "Enter a key: ";
	cin >> key;
	cout << key << " occurs ";
	count = CountKey(L,key);
	if (count != 1)
		cout << count << " times in the list." << endl;
	else
		cout << "1 time in the list." << endl;

	// use DeleteKey to remove all occurrences of key in L.
	// print the new list
	cout << "Deleting " << key << " from the list:" << endl;
	DeleteKey(L,key);
	cout << "List L: ";
	PrintList(L);
	cout << endl;
}

/*
<Run>

List L: 3  5  7  7  7  7  7  8  15  35
Enter a key: 7
7 occurs 5 times in the list.
Deleting 7 from the list:
List L: 3  5  8  15  35
*/

⌨️ 快捷键说明

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