#include #include "arlist.h" using namespace std; bool insert(tItemType newitem, tNode list[], int& head, int& n, int capacity) // Note: If n==0, then head is assumed to be initialized to -1 { int current; // index of node under current consideration int previous = NONE; // index of prior node if (n >= capacity) return false; else { // insert new item into array list[n].item = newitem; // is this first item in list? if (n==0 || newitem < list[head].item) { list[n].next = head; head = n; } else { // traverse the list current = head; while ( current != NONE && list[current].item < newitem ) { previous = current; current = list[current].next; } // update the "next" values list[n].next = list[previous].next; list[previous].next = n; } ++n; return true; } } void traverse(tNode list[], int head) { int current = head; // index of node under current consideration while ( current != NONE ) { cout << list[current].item << endl; current = list[current].next; } return; }