Ejemplo n.º 1
0
int main()
{

  ifstream inFile;       // file containing operations
  ofstream outFile;      // file containing output
  string inFileName;     // input file external name
  string outFileName;    // output file external name
  string outputLabel;     
  string command;        // operation to be executed
  
  int number;
  ItemType item;
  UnsortedType list;
  bool found;
  int numCommands;


  // Prompt for file names, read file names, and prepare files
  cout << "Enter name of input command file; press return." << endl;
  cin  >> inFileName;
  inFile.open(inFileName.c_str());

  cout << "Enter name of output file; press return." << endl;
  cin  >> outFileName;
  outFile.open(outFileName.c_str());

  cout << "Enter name of test run; press return." << endl;
  cin  >> outputLabel;
  outFile << outputLabel << endl;
  if (!inFile)
  {
    cout << "file not found" << endl;
	exit(2);
  }
  inFile >> command;

  numCommands = 0;
  while (command != "Quit")
  { 
    if (command == "PutItem")
    {
      inFile >> number; 
      item.Initialize(number);
      list.PutItem(item);
      item.Print(outFile);
      outFile << " is in list" << endl;
    }
    else if (command == "DeleteItem")
Ejemplo n.º 2
0
int main()
{
    ItemType item[MAX_ITEM];
    SortedType list;
    
    item[0].Initialize(67);
    item[1].Initialize(89);
    item[2].Initialize(100);
    item[3].Initialize(12);
    item[4].Initialize(32);
    
    
    for(int i = 0; i < MAX_ITEM; i++)
    {
        list.InsertItem(item[i]);
    }
    
    list.IsFull() ? cout << "List is not empty" : cout << "list is empty";
    cout << endl;
    
    cout << "Length of the list is : " << list.LengthIs() << endl;
    
    cout << "Contents of the list : ";
    FOR()
    {
        ItemType printItem;
        
        list.GetNextElement(printItem);
        printItem.Print();
    }
    cout << endl;
    cout << endl;
    
    
    int key;
    ItemType deleteKey;
    cout << "Enter what you want to delete : ";
    cin >> key;
    deleteKey.Initialize(key);
    
    list.DeleteItem(deleteKey);
    
    cout << "After deletion the length of the list : " << list.LengthIs() << endl;
    cout << "Contents of the list  after deletion : ";
    list.ResetList();
    for(int i = 0; i < list.LengthIs(); i++)
    {
        ItemType printItem;
        
        list.GetNextElement(printItem);
        printItem.Print();
    }

    cout << endl;
    
    cout << "Emptying the list........." << endl;
    list.MakeEmpty();
    list.IsFull() ? cout << "List is not empty" : cout << "list is empty";
    cout << endl;
    
    cout << "Resetting the list.............." << endl;
    list.ResetList();
    
    
    
    return 0;
}