mapavl-driver.cpp

来自「The existed tree implementation」· C++ 代码 · 共 95 行

CPP
95
字号
#include <string>    // For the STL string class#include <stream.h>  // For the cout and the << operator#include "MapAVL.h"int main(){  MapAVL<string,int>  A;  cout << "\nCreating a new map A from strings to integers.\n";  cout << "A currently has " << A.size() << " <key,value> pair(s).\n";  if (A.empty("blue"))   cout << "A[blue] does not exist.\n";   else  cout << "A[blue] = "   << A["blue"]   << endl;  if (A.empty("green"))  cout << "A[green] does not exist.\n";  else  cout << "A[green] = "  << A["green"]  << endl;  if (A.empty("yellow")) cout << "A[yellow] does not exist.\n"; else  cout << "A[yellow] = " << A["yellow"] << endl;  if (A.empty("red"))    cout << "A[red] does not exist.\n";    else  cout << "A[red] = "    << A["red"]    << endl;  A["red"] = 7;  cout << "\nSetting A[red] to be 7.\n";  cout << "A currently has " << A.size() << " <key,value> pair(s).\n";  if (A.empty("blue"))   cout << "A[blue] does not exist.\n";   else  cout << "A[blue] = "   << A["blue"]   << endl;  if (A.empty("green"))  cout << "A[green] does not exist.\n";  else  cout << "A[green] = "  << A["green"]  << endl;  if (A.empty("yellow")) cout << "A[yellow] does not exist.\n"; else  cout << "A[yellow] = " << A["yellow"] << endl;  if (A.empty("red"))    cout << "A[red] does not exist.\n";    else  cout << "A[red] = "    << A["red"]    << endl;  A["yellow"] = 10;  cout << "\nSetting A[yellow] to be 10.\n";  cout << "A currently has " << A.size() << " <key,value> pair(s).\n";  if (A.empty("blue"))   cout << "A[blue] does not exist.\n";   else  cout << "A[blue] = "   << A["blue"]   << endl;  if (A.empty("green"))  cout << "A[green] does not exist.\n";  else  cout << "A[green] = "  << A["green"]  << endl;  if (A.empty("yellow")) cout << "A[yellow] does not exist.\n"; else  cout << "A[yellow] = " << A["yellow"] << endl;  if (A.empty("red"))    cout << "A[red] does not exist.\n";    else  cout << "A[red] = "    << A["red"]    << endl;  A["blue"] = 9;  cout << "\nSetting A[blue] to be 9.\n";  cout << "A currently has " << A.size() << " <key,value> pair(s).\n";  if (A.empty("blue"))   cout << "A[blue] does not exist.\n";   else  cout << "A[blue] = "   << A["blue"]   << endl;  if (A.empty("green"))  cout << "A[green] does not exist.\n";  else  cout << "A[green] = "  << A["green"]  << endl;  if (A.empty("yellow")) cout << "A[yellow] does not exist.\n"; else  cout << "A[yellow] = " << A["yellow"] << endl;  if (A.empty("red"))    cout << "A[red] does not exist.\n";    else  cout << "A[red] = "    << A["red"]    << endl;  A["red"] = 5;  cout << "\nSetting A[red] to be 5.\n";  cout << "A currently has " << A.size() << " <key,value> pair(s).\n";  if (A.empty("blue"))   cout << "A[blue] does not exist.\n";   else  cout << "A[blue] = "   << A["blue"]   << endl;  if (A.empty("green"))  cout << "A[green] does not exist.\n";  else  cout << "A[green] = "  << A["green"]  << endl;  if (A.empty("yellow")) cout << "A[yellow] does not exist.\n"; else  cout << "A[yellow] = " << A["yellow"] << endl;  if (A.empty("red"))    cout << "A[red] does not exist.\n";    else  cout << "A[red] = "    << A["red"]    << endl;  A["green"] = 2;  cout << "\nSetting A[green] to be 2.\n";  cout << "A currently has " << A.size() << " <key,value> pair(s).\n";  if (A.empty("blue"))   cout << "A[blue] does not exist.\n";   else  cout << "A[blue] = "   << A["blue"]   << endl;  if (A.empty("green"))  cout << "A[green] does not exist.\n";  else  cout << "A[green] = "  << A["green"]  << endl;  if (A.empty("yellow")) cout << "A[yellow] does not exist.\n"; else  cout << "A[yellow] = " << A["yellow"] << endl;  if (A.empty("red"))    cout << "A[red] does not exist.\n";    else  cout << "A[red] = "    << A["red"]    << endl;  A["yellow"] = -2;  cout << "\nSetting A[yellow] to be -2.\n";  cout << "A currently has " << A.size() << " <key,value> pair(s).\n";  if (A.empty("blue"))   cout << "A[blue] does not exist.\n";   else  cout << "A[blue] = "   << A["blue"]   << endl;  if (A.empty("green"))  cout << "A[green] does not exist.\n";  else  cout << "A[green] = "  << A["green"]  << endl;  if (A.empty("yellow")) cout << "A[yellow] does not exist.\n"; else  cout << "A[yellow] = " << A["yellow"] << endl;  if (A.empty("red"))    cout << "A[red] does not exist.\n";    else  cout << "A[red] = "    << A["red"]    << endl;  A.erase("red");  cout << "\nRemoving A[red]\n";  cout << "A currently has " << A.size() << " <key,value> pair(s).\n";  if (A.empty("blue"))   cout << "A[blue] does not exist.\n";   else  cout << "A[blue] = "   << A["blue"]   << endl;  if (A.empty("green"))  cout << "A[green] does not exist.\n";  else  cout << "A[green] = "  << A["green"]  << endl;  if (A.empty("yellow")) cout << "A[yellow] does not exist.\n"; else  cout << "A[yellow] = " << A["yellow"] << endl;  if (A.empty("red"))    cout << "A[red] does not exist.\n";    else  cout << "A[red] = "    << A["red"]    << endl;  cout << endl << "Testing the dump function:" << endl;  Pair<string,int> array[10];  A.dump(array);  for(int i=0; i < A.size(); i++)  {    cout << "A[" << array[i].getLeft() << "] = " << array[i].getRight() << endl;  }  return 0;}

⌨️ 快捷键说明

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