#ifndef __List_h__ #define __List_h__ class List { private: struct node { int data; double key; node *next; // fast assignment node(double key_, int data_) { key = key_; data = data_; next = NULL; } }; // head of the list found here struct node *head; int count; public: List() { head = NULL; count = 0; } ~List() { // do nothing - should probably free the list! } void Insert(double key, int data) { count++; node *tmp = new node(key, data); // if new fails, will throw exception, so it's ok // have to insert it in order! if (head == NULL) { head = tmp; } else { // special case: tmp becomes new head of list if (tmp->data < head->data) { tmp->next = head; head = tmp; } else { node *curr = head->next; node *prev = head; while (curr) { if (tmp->data < curr->data) { break; } prev = curr; curr = curr->next; } // put in place! tmp->next = curr; prev->next = tmp; } } } void Print() { printf("Total number of integers received: %d\n", count); printf("***************************************\n"); node *curr = head; while (curr) { printf("%d (%d)\n", curr->data, (int)(1e3*curr->key + 0.5)); curr = curr->next; } } }; #endif // __List_h__