int main()
{
	SinglyLinkedList list;
	
	list.insertOrdered("Mike", 1105);
	list.insertOrdered("Rob",  750);
	list.insertOrdered("Paul", 720);
	list.insertOrdered("Anna", 660);
	list.insertOrdered("Rose", 590);
	list.insertOrdered("Jack", 510);
	list.insertOrdered("Jill", 740);

	cout << "List after insertions :" << endl;
	list.print();

	list.removeOrdered("Adam", 610);	// Bu eleman listede yok !

	list.removeOrdered("Jack", 510);
	list.removeOrdered("Mike", 1105);
	list.removeOrdered("Paul", 720);

	cout << "\nList after removals (Jack, Mike, Paul) :" << endl;
	list.print();

	list.removeOrdered("Rose", 590);
	list.removeOrdered("Rob",  750);	
	list.removeOrdered("Anna", 660);
	list.removeOrdered("Jill", 740);

	cout << "\nList after removals (Rose, Rob, Anna, Jill ) :" << endl;
	list.print();
    
    return 0;
	//::getchar();
}
Beispiel #2
0
int main()
{
    //test
    TestList testList;
    QTest::qExec(&testList);
    //end test
    cout << "Wait a second";
    sleep(1);//for debug(sometimes occures mistake of debugger without sleep();)
    cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b";

    cout << "Singly linked list:\n";
    SinglyLinkedList list;
    list.addValue(2);
    list.addPos(5, 4);
    list.addPos(5, 3);
    list.addPos(1, 99);
    list.deletePos(1);
    list.print();

    cout << "\nDoubly linked list:\n";
    DoublyLinkedList list2;
    list2.addValue(2);
    list2.addPos(5, 4);
    list2.addPos(5, 3);
    list2.addPos(1, 99);
    list2.print();
    list2.deletePos(1);
    list2.print();

    cout << "\nSingly linked list heap try:\n";
    SinglyLinkedList* listH1 = new SinglyLinkedList();
    listH1->addValue(3);
    listH1->addValue(5);
    listH1->addValue(7);
    listH1->addPos(1, 2);
    listH1->print();
    delete listH1;

    cout << "\nDoubly linked list heap try:\n";
    DoublyLinkedList* listH2 = new DoublyLinkedList();
    listH2->addValue(3);
    listH2->addValue(5);
    listH2->addValue(7);
    listH2->addPos(1, 2);
    listH2->print();
    delete listH2;

    return 0;
}
int main() 
{
    // Grab current cout flags, used for when the stream is altered and the user wants
    //   to reset it to the default values: 
    ios::fmtflags f( cout.flags() );

    // Test 1:
    {
      SinglyLinkedList<char>* list = new SinglyLinkedList<char>();

      char var = 'A';

      for (int i = 1; i <= 10; i++) 
        {
        list->pushBack(var);
        var++;
      }

      cout << endl << "Test 1 - Char list:" << endl << "\t";
      list->print();
        cout << endl;
    }

    // Reset cout stream flags:
    cout.flags(f);

    // Test 2:
    {
        DoublyLinkedList<myType>* list = new DoublyLinkedList<myType>();

        myType var = 1;

        for (int i = 1; i <= 10; i++) 
        {
            list->pushBack(var);
            var++;
        }

        cout << endl << "Test 2 - Int list:" << endl << "\t";
        list->print();
        cout << endl;
    }

    // Reset cout stream flags:
    cout.flags(f);

    // Test 3:
    {
        BinaryTree<int>* bt = new BinaryTree<int>();

        // Insert a bunch of stuff:
        bt->insert(11);
        bt->insert(6);
        bt->insert(8);
        bt->insert(19);
        bt->insert(4);
        bt->insert(10);
        bt->insert(5);
        bt->insert(17);
        bt->insert(43);
        bt->insert(49);
        bt->insert(31);

        // Print tree preOrderTraversal:
        cout << endl << "Binary Tree PreOrderTravesal:" << endl << "\t";
        bt->preOrderTraversal();
        cout << endl;

        // Print tree inOrderTraversal:
        cout << endl << "Binary Tree InOrderTravesal:" << endl << "\t";
        bt->inOrderTraversal();
        cout << endl;

        // Print tree postOrderTraversal:
        cout << endl << "Binary Tree PostOrderTravesal:" << endl << "\t";
        bt->postOrderTraversal();
        cout << endl;
    }

    cout << endl;

    return 0;
}