// Project LinkedList // File main2.cpp // Create ordered linked list. #include using namespace std; #include "Node.h" int main() { // Create sorted linked list from back to front. // Use header (item == 0) and // trailer (item == 999) nodes. int i, data[] = {999, 91, 86, 75, 35, 0}; Node *head, *p; head = new Node(data[0]); // Create list from data array. for(i = 1; i <= 5; i++) { p = new Node(data[i]); p -> set_next(head); head = p; } // Print list. for(p = head; p != NULL; p = p -> get_next()) cout << p -> get_item() << " "; cout << endl; int new_item = 52; // Find insertion point. for(p = head; p -> get_next() -> get_item() < new_item; p = p -> get_next()) ; // Insert new node containing item 52 into sorted linked list. Node *q = new Node(new_item); q -> set_next(p -> get_next()); p -> set_next(q); // Print updated list. for(p = head; p != NULL; p = p -> get_next()) cout << p -> get_item() << " "; cout << endl; return EXIT_SUCCESS; }