Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DoublyListNode.h
- #pragma once
- template <class T > class DoublyList;
- template<class T >
- class DoublyListNode
- {
- friend class DoublyList< T >; // Make Double List a friend
- public:
- DoublyListNode( const T &);
- T getData() const;
- private:
- T data;
- DoublyListNode< T > *nextPtr;
- DoublyListNode < T > *prePtr; // precede
- }; // end class DoublyListNode constructor
- template < class T >
- DoublyListNode< T > :: DoublyListNode( const T &info) : data(info), nextPtr(NULL), prePtr(NULL)
- {
- // empty body
- } // end DoublyListNode constructor
- template< class T >
- T DoublyListNode< T > :: getData() const
- {
- return data;
- }
- // main.cpp DoublyList
- using namespace std;
- #include "DoublyList.h"
- #include "DoublyListNode.h"
- int menu();
- int main()
- {
- //cout << "Hello World\n";
- DoublyList< int > integerList;
- int index = 1, opt;
- int value;
- do {
- opt = menu();
- switch(opt) {
- case 1:
- cout << "Entre un numero: ";
- cin >> value;
- integerList.insert(1, value);
- integerList.print();
- break;
- case 2:
- cout << "Final Enter a number: ";
- cin >> value;
- index = integerList.getLength();
- integerList.insert(index+1, value);
- integerList.print();
- break;
- case 3:
- cout << "Enter a number: ";
- cin >> value;
- cout << "Enter the index : ";
- cin >> index;
- integerList.insert(index, value);
- integerList.print();
- break;
- case 4:
- cout << "Enter the index: ";
- cin >> index;
- integerList.remove(index);
- integerList.print();
- break;
- case 5:
- cout << "View the content of the index: ";
- cin >> index;
- integerList.retrieve(index, value);
- cout << "Index: " << index << "Value: " << value << endl;
- integerList.print();
- break;
- case 6:
- integerList.print();
- break;
- case 7:
- DoublyList< int > newList( integerList);
- cout << "Original List\n";
- integerList.print();
- cout << "New List\n";
- newList.print();
- } // end switch
- } while( opt != 8);
- return 0;
- } // end main
- int menu()
- {
- int opt;
- cout << "Main Menu\n";
- cout << "1.Add a node at the beginning of the list\n";
- cout << "2. Add a node at the end of the list\n";
- cout << "3.Add a node on the desired index of the list\n";
- cout << "4.Eliminate a node on the desired position\n";
- cout << "5.View the content of a node\n";
- cout << "6.Print List\n";
- cout << "7.Create another list aside from the one created\n";
- cout << "8.Exit Program\n";
- cout << "Enter an option:";
- cin >> opt;
- return opt;
- } // end menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement