Node and List

Hello, Im very very new at C++, I have this assignment that I can't figure out, if anybody could me, I'll be very grateful.


Create a List class with the following interface (at a minimum):
bool addItem(Node&) //add an item to the list, return true on success
Node* getLargestNode( ) //return the largest value stored in the list
In addition, create a Node class that stores an integer. The Nodes will be linked together to form the List. Your driver program should accept ten integers from the console, create new Nodes, store them in the list, then display the largest value in the list.
You'll end up with at least two objects: the List object, and the Node object. You’ll want to think about what a node is and what a list is, and what behaviors each should have. For example, the List shouldn’t store the highest integer in the list…instead it should ask each Node its value, and if the Node contains the highest value the List has seen, it should store a pointer to that Node.
getLargestNode( ) should iterate the list…start at the top and look at each node in turn until it reaches the bottom of the list. It returns a Node, so you can use the method in main( ) to find and print the value of the largest node.

Thank you
You are very new to C++ but want to write a linked list? Have you ever worked with pointers before? I could give you the code to do this but it wouldn't make sense to you.

Without making this a template class, this is probably how you want to get started.

1
2
3
4
5
6
7
8
9
10
11
typedef int item;   // typedefs an integer to an item
                     // Since your list can use item you can typedef
                     // any C++ data type to work with you list

// This is a node. It contains storage for an item (data) 
// and a link to the next item (next). The link is a pointer to a node

struct Node {
    item data;
    Node* next;
};
Last edited on
Topic archived. No new replies allowed.