Hey guys I'm trying to do this program but when I run it doesn't work...
Hopefully some of you will be able to see the error.
Phase I (30 points)
• Struct Node
• Class unsortedLinkedList (or shorter name) with a private HEAD pointer.
Include constructor method to make HEAD null.
• Main method that establishes the mylist object and calls the supporting
methods (insert, displayAll, …)
• Insert Method that places a new node at the beginning of the list
• DisplayAll method that displays each node’s info value on the screen
Phase II (40 points)
• Search method that received an int value as intput and returns true or false
back to main to indicate if the value was found or not.
• Delete method that deletes a node at any location within the linked list.
• Furthermore, the search and delete methods should not “bomb out” with an
empty list.
*** End of Program Assignment ***
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
// LinkedList.cpp : Defines the entry point for the console application.
//
#include <iostream>
using namespace std;
//** structure node ***
struct Node
{
int info;
Node* Next;
};
//*** class LinkedList ****
class LinkedList
{
public:
LinkedList();
void insertItem(int item);
void DisplayAll();
private:
Node* H;
};
LinkedList::LinkedList()
{
H=NULL;
}
void LinkedList::DisplayAll()
{
Node* curr;
// for (curr = H; curr != NULL; curr = curr -> Next)
// std::cout << curr->info << std::endl;
std::cout << "displayAll FUnction << std::endl";
curr = H;
while (curr)
{
std::cout << curr->info << std::endl;;
curr = curr-> Next;
cout<<endl;
}
}
void LinkedList::insertItem(int item)
{
Node*newNode;
newNode = new Node;
newNode->info = item;
newNode->Next=H;
H=newNode;
}
//*** Main ***
int main()
{
std::cout << "Hello world" << std::endl;
LinkedList mylist;
mylist.insertItem(12);
//mylist.insertItem(15);
//mylist.insertItem(20);
//mylist.insertItem(100);
mylist.DisplayAll();
return(0);
}
|