Sample Program Using an Unordered List
#include <iostream.h> #include "arrlist.h" int main() { int ok; int anum; List mynums; // add some numbers to the list and then print the list ok = mynums.insert(1,10); ok = mynums.insert(2,20); ok = mynums.insert(3,30); ok = mynums.insert(2,40); ok = mynums.insert(3,80); cout << "The list contains:\n"; for (int i = 1 ; i <=mynums.length() ; i++) { mynums.retrieve(i,anum); cout << anum << " "; } cout << endl; // delete some items from the list and then print it again ok = mynums.del(3); ok = mynums.del(1); cout << "\nAfter deleting, the list contains:\n"; for (i = 1 ; i <= mynums.length() ; i++) { mynums.retrieve(i,anum); cout << anum << " "; } cout << endl; }
Output
The list contains: 10 40 80 20 30 After deleting, the list contains: 40 20 30
Email Me | Office Hours | My Home Page | Department Home | MCC Home Page