20-CS-122-001 Computer Science II Spring 2012
Array Implementation With Class List

Virtual functions, classes, inheritance, lists, queues, stacks, applications

Prev      Next      Lectures      Makefile      uselist.3.cc      list.3.h      list.3.cc      power point

// Problem solved:
//  1. do not have to ask for memory from OS every time a change is made
//
// Problem created:
//  1. user may not be able to add an object to a "full" list
//
// Not a problem:
//  1. much more complex code is unnoticed by a user

// Note: I lied.  List implementation in list.3.cc and list.3.h also
// deletes copies but is less eager at making copies in the first place:
// it does not make a copy of a copy!

#include <iostream>
#include "list.3.h"
using namespace std;

bool find (void *item, void *what) { return *(int*)item == *(int*)what; }
void disp (void *item) {  cout << *(int*)item;  }

int main () {
   List l(find, disp);
   List m(find, disp);
   List n(find, disp);
   l += new int(2);
   l += new int(4);
   l += new int(6);
   l *= new int(1);
   l *= new int(9);
   l *= new int(8);
   cout << m + new int(2) + new int(4) + new int(6)
	<< "--------------------------\n";
   m = m + new int(2) + new int(4) + new int(6);
   m = m * new int(1) * new int(9) * new int(8);
   n = n * new int(1)*new int(9)*new int(8)+new int(2)+new int(4)+new int(6);
   cout << l << m << n << "--------------------------\n";
   l <= new int(1);
   cout << l;
   l >= new int(4);
   cout << l;
   l >= new int(1);
   cout << l;
   l -= new int(1);
   cout << l;
   l -= new int(9);
   cout << l;
}