UB CS 400 - Study Guide (5 pages)

Previewing pages 1, 2 of 5 page document View the full content.
View Full Document

Study Guide



Previewing pages 1, 2 of actual document.

View the full content.
View Full Document
View Full Document

Study Guide

77 views


Pages:
5
School:
University of Bridgeport
Course:
Cs 400 - Object Oriented Programming Using C++
Unformatted text preview:

Handout 16 J Dichter ifndef TmpLIST SEEN define TmpLIST SEEN File List h include iostream h linked list template CS 400 forward teamplate class declaration template class T class Cell template class T class ListIterator type T must define operator and overload template class T class List friend class ListIterator T public List head NULL empty list constructor List T c list with first cell head new Cell T c NULL head new Cell T c Cell T first return head first cell static Cell T next Cell T p next cell return p p next p static int is end Cell T p end test return p NULL Cell T last last cell Cell T find T c first value equals c int substitute T r T s r for first s on list int remove T c c from entire list void remove Cell T cell remove given cell int shorten int n remove first n cells static T content Cell T p return p value int put on T c insert in front int insert T c Cell T cell insert after cell int append T c insert at end return insert c last int is empty return is end head void display ostream out display from p to end Cell T p const void display ostream out const display out head display whole list List destructor private int equal T T equality test Cell T head first cell of list void free free all cells Handout 16 J Dichter template class T class ListIterator public ListIterator List T x l x cur pre x first int operator T n returns next entry in n void del erases last retrieved entry from list private List T l Cell T cur Cell T pre template class T class Cell friend class List T friend class ListIterator T private T value return val void value T v val v set value T val store pointer to type T Cell T next Cell T c Cell T ptr NULL val c next ptr constructor endif CS 400 Handout 16 J Dichter CS 400 File List C include List h template class T inline int List T equal T r T s return r s template class T List T List free template class T void List T free private method Cell T n p head while p n p next delete p p n template class T int List T shorten int n while n head Cell T tmp head head head next delete tmp return n template class T int List T remove T c Cell T tmp p head int count 0 while p next treat all but head cell if equal p next value c count tmp p next p next tmp next delete tmp free up store else p p next if equal head value c treat head cell tmp head head head next delete tmp count return count number of items removed Handout 16 J Dichter template class T void List T remove Cell T z Cell T tmp if head z tmp head head head next delete tmp return Cell T p head while p next if p next z tmp p next p next p next next delete tmp return else p p next return CS 400 del list cell treat head cell treat other cells free up store no entry is 0 template class T int List T put on T c Cell T tmp new Cell T c head if tmp head tmp return 0 else return 1 failed insert after entry e template class T int List T insert T c Cell T e Cell T tmp new Cell T c next e if tmp if e e next tmp else head tmp return 0 else return 1 failed template class T Cell T List T last Cell T p head while p p next p p next return p Handout 16 J Dichter CS 400 template class T Cell T List T find T c for Cell T p head p p p next if equal p value c return p return NULL c not on list template class T int List T substitute T r T s for Cell T p head p p p next if equal p value s p value r return 0 return 1 s not on list display from p to end template class T void List T display ostream out Cell T p const out while p out p value call overloaded if p p next out out n template class T int ListIterator T operator T n pre cur if pre cur pre next n pre value return 1 else return 0 template class T void ListIterator T del l remove pre


View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Study Guide and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Guide and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?