20-CS-122-001 Computer Science II Spring 2012
List Class Using an Array of Type void *

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

Prev      Next      Lectures      list.3.h      list.3.cc

#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 = new List(find, disp);
   l->add_frnt(new int(2));
   l->add_frnt(new int(4));
   l->add_frnt(new int(6));
   l->add_rear(new int(1));
   l->add_rear(new int(9));
   l->add_rear(new int(8));
   l->add_frnt(new int(7));
   l->add_frnt(new int(0));
   l->show_fwd();
   l->movetofront(new int(1));
   l->show_fwd();
   l->movetorear(new int(4));
   l->show_fwd();
   l->movetorear(new int(1));
   l->show_fwd();
   l->remove(new int(1));
   l->show_fwd();
   l->remove(new int(9));
   l->show_fwd();
}