📄 pex9_11.cpp
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -