// unsorteddr.cpp 

#include <iostream>
#include "UnsortedType.h"   //templated, linked list implementation

using namespace std;

struct thingee {    //example struct
  int i;
  char c;
  float f;
};

int main() {

  UnsortedType<int> L1;    
  UnsortedType<char> L2;   
  UnsortedType<thingee> L3; 
  int num, i;
  char ch;
  thingee t;
  bool found;

  // int list
  cout << "Enter numbers, negative number to stop" << endl;
  do {
    cin >> num;
    if (num >= 0)
      L1.InsertItem(num);  //"prepend" to beginning of list
  } while (num >= 0);

  cout << endl << "Stuff that's now in the list: " << endl;
  //iterate over list
  L1.ResetList();
  for (i=0; i<L1.LengthIs(); i++) {
    L1.GetNextItem(num);
    cout << num << " ";
  }
  cout << endl;

  cout << "Enter values to search for in the list: [-1 to stop]: " << endl;
  cin >> num;
  while (num != -1) {
    L1.RetrieveItem(num,found);
    if (found)
      cout << "   Found it" << endl;
    else
      cout << "   Not there" << endl;
    cin >> num;
  }

  cout << endl << "Enter values to delete from the list: [-1 to stop] ";
    //       << endl << "OK to try values not in list" << endl;
  cin >> num;
  while (num != -1) {
    L1.DeleteItem(num);
    cin >> num;
  }

  cout << endl << "Stuff that's now in the list: " << endl;
  L1.ResetList();
  for (i=0; i<L1.LengthIs(); i++) {
    L1.GetNextItem(num);
    cout << num << " ";
  }
  cout << endl;

/* //will be uncommented to test your homework
  cout << "Largest value in the list is:  ";
  L1.FindMax(num);
  cout << num << endl;

  cout << endl << "Stuff that's in the reversed list: " << endl;
  L1.Reverse();
  L1.ResetList();
  for (i=0; i<L1.LengthIs(); i++) {
    L1.GetNextItem(num);
    cout << num << " ";
  }
  cout << endl;
*/

  cout << endl << endl;
  cout << "----------------------------------------------------------" << endl;


  // char list
  cout << "Enter characters, pound sign (#) to stop" << endl;
  do {
    cin >> ch;
    if (ch != '#')
      L2.InsertItem(ch);
  } while (ch != '#');

  cout << endl << "Stuff that's now in the list: " << endl;
  L2.ResetList();
  for (i=0; i<L2.LengthIs(); i++) {
    L2.GetNextItem(ch);
    cout << ch << " ";
  }
  cout << endl;

  cout << "Enter values to search for in the list: [# to stop]: " << endl;
  cin >> ch;
  while (ch != '#') {
    L2.RetrieveItem(ch,found);
    if (found)
      cout << "   Found it" << endl;
    else
      cout << "   Not there" << endl;
    cin >> ch;
  }

  cout << endl << "Enter values to delete from the list: [# to stop] ";
    //       << endl << "OK to try values not in list" << endl;
  cin >> ch;
  while (ch != '#') {
    L2.DeleteItem(ch);
    cin >> ch;
  }

  cout << endl << "Stuff that's now in the list: " << endl;
  L2.ResetList();
  for (i=0; i<L2.LengthIs(); i++) {
    L2.GetNextItem(ch);
    cout << ch << " ";
  }
  cout << endl;

/* //will be uncommented to test your homework
  cout << "Largest value in the list is:  ";
  L2.FindMax(ch);
  cout << ch << endl;

  cout << endl << "Stuff that's in the reversed list: " << endl;
  L2.Reverse();
  L2.ResetList();
  for (i=0; i<L2.LengthIs(); i++) {
    L2.GetNextItem(ch);
    cout << ch << " ";
  }
  cout << endl;
*/
  cout << endl << endl;
  cout << "----------------------------------------------------------" << endl;


  // thingee list
  cout << "Enter thingee records (int, char, float), negative number to stop" << endl;
  do {
    cin >> t.i >> t.c >> t.f;
    if (t.i >= 0)
      L3.InsertItem(t);
  } while (t.i >= 0);

  cout << endl << "Stuff that's now in the list: " << endl;
  L3.ResetList();
  for (i=0; i<L3.LengthIs(); i++) {
    L3.GetNextItem(t);
    cout << t.i << "  " << t.c << "  " << t.f << endl;
  }



  //can't do RetrieveItem because == is not defined on struct thingee
  //can't do DeleteItem because == is not defined on struct thingee
  //can't do FindMax because < is not defined on struct thingee
  //We would have to overload these operators to work on thingee structs.
  // See thingee.cpp for how to do so.

/* //will be uncommented to test your homework
  cout << endl << "Stuff that's in the reversed list: " << endl;
  L3.Reverse();
  L3.ResetList();
  for (i=0; i<L3.LengthIs(); i++) {
    L3.GetNextItem(t);
    cout << t.i << "  " << t.c << "  " << t.f << endl;
  }
*/

  cout << endl;
  cout << "----------------------------------------------------------" << endl;

}
