Search
Home
Saved
1.5K views
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Sheet Music
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
#ifndef VECTOR_H #define VECTOR_H #define vector Vector class ArrayIndexOutOfBounds { }; template class vector { public: explicit vector( int theSize = 0 ) : currentSize( theSize ) { objects = new Object[ currentSize ]; } vector( const vector & rhs ) : objects( NULL ) { operator=( rhs ); } ~vector( ) #ifndef WIN32 { delete [ ] objects; } #else { if( currentSize != 0 ) delete [ ] objects; } #endif size( ) const Master your int semester with Scribd { return currentSize; } Object & operator[]( int index & The New York Times
Read Free Foron 30this Days Sign up to vote title )
Not useful Cancel anytime.
Useful
{ Special offer for students: Only $4.99/month.
if( index < 0 || index >= currentSize )
#ifndef NO_CHECK
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Download
Magazines
News
Documents
Sheet Music
Quest2
1
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
const vector & operator = ( const vector & rhs ); void resize( int newSize ); private: int currentSize; Object * objects; }; #include "vector.cpp" #endif
#ifndef VECTOR_CPP_ #define VECTOR_CPP_ #include "vector.h" template const vector & vector::operator=( const vector & rhs ) { if( this != &rhs ) { #ifdef WIN32 if( currentSize != 0 ) #endif delete [ ] objects; currentSize = rhs.size( ); objects = new Object[ currentSize ]; for( int k = 0; k < currentSize; k++ ) objects[ k ] = rhs.objects[ k ]; } return *this; }
Master your semester with Scribd template vector::resize( int newSize & The New{void York Times
)
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Special offer for students:Object Only $4.99/month. *oldArray = objects; int numToCopy = newSize < currentSize ? newSize : currentSize;
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Sheet Music
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
: A simple recursive routine with a test program
#include
/* 1*/ /* 2*/ /* 3*/
int f( int x ) { if( x == 0 ) return 0; else return 2 * f( x - 1 ) + }
x * x;
int main( ) { cout << "f(5) = " << f( 5 ) << endl; return 0; }
Master your semester with Scribd & The New York Times : Header file for linked list LinkedList.h Special offer for students: Only $4.99/month.
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents Sheet Music
Quest2
1
Download
1.5K views
// // position p // // // // // //
of 51
ListItr first( ) void insert( x, p )
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
--> Return first position --> Insert x after current iterator
void remove( x ) --> Remove x ListItr find( x ) --> Return position that views x ListItr findPrevious( x ) --> Return position prior to x ******************ERRORS******************************** No special errors
template class List; // Incomplete declaration. template class ListItr; // Incomplete declaration. template class ListNode { ListNode( const Object & theElement = Object( ), ListNode * n = NULL ) : element( theElement ), next( n ) { } Object element; ListNode *next; friend class List; friend class ListItr; };
template class List { public: List( ); List( const List & rhs ); ~List( );
Master your semester with Scribd & The New York Times bool isEmpty( ) const;
Read Free Foron 30this Days Sign up to vote title
Special offer for students: Only $4.99/month. void makeEmpty( ); ListItr zeroth( ) const;
Not useful Cancel anytime.
Useful
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Quest2
1
Download
Magazines
News
Documents
1.5K views
Sheet Music
// // // // // //
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
CONSTRUCTION: Package friendly only, with a ListNode
******************PUBLIC OPERATIONS********************* bool isPastEnd( ) --> True if past end position in list void advance( ) --> Advance (if not already null) Object retrieve --> Return item in current position
template class ListItr { public: ListItr( ) : current( NULL ) { } bool isPastEnd( ) const { return current == NULL; } void advance( ) { if( !isPastEnd( ) ) current = current->next; } const Object & retrieve( ) const { if( isPastEnd( ) ) throw BadIterator( ); return current->element; } private: ListNode *current;
// Current position
ListItr( ListNode *theNode ) : current( theNode ) { } friend class List; // Grant access to constructor }; #include "LinkedList.cpp" #endif
LinkedList.cpp : Implementation for linked list
#include "LinkedList.h"
Master your semester with Scribd /** * Construct the list & The New York */ Times template Special offer for students: Only $4.99/month. List::List( )
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Download
Magazines
News
Documents
1.5K views
Sheet Music
Quest2
1
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
* Destructor */ template List::~List( ) { makeEmpty( ); delete header; } /** * Test if the list is logically empty. * return true if empty, false otherwise. */ template bool List::isEmpty( ) const { return header->next == NULL; } /** * Make the list logically empty. */ template void List::makeEmpty( ) { while( !isEmpty( ) ) remove( first( ).retrieve( ) ); } /** * Return an iterator representing the header node. */ template ListItr List::zeroth( ) const { return ListItr( header ); } Read Free Foron 30this Days Sign up to vote title /** Useful Not useful * Return an iterator representing the first node in the list. Cancel anytime. Special offer for students: Only $4.99/month. * This operation is valid for empty lists. */
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
p.current->next = new ListNode( x, p.current-
Sheet Music
>next ); } /** * Return iterator corresponding to the first node containing an item x. * Iterator isPastEnd if item is not found. */ template ListItr List::find( const Object & x ) const { /* 1*/ ListNode *itr = header->next; /* 2*/ /* 3*/
while( itr != NULL && itr->element != x ) itr = itr->next;
/* 4*/
return ListItr( itr ); }
/** * Return iterator prior to the first node containing an item x. */ template ListItr List::findPrevious( const Object & x ) const { /* 1*/
ListNode *itr = header;
/* 2*/ /* 3*/
while( itr->next != NULL && itr->next->element != x ) itr = itr->next;
/* 4*/
return ListItr( itr ); }
/** * Remove the first occurrence of an item x. */ Read Free Foron 30this Days Sign up to vote title template Not useful Useful void List::remove( const Object & x anytime. ) Cancel Special offer for students: Only $4.99/month. { ListItr p = findPrevious( x );
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents Sheet Music
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
const List & List::operator=( const List & rhs ) { ListItr ritr = rhs.first( ); ListItr itr = zeroth( ); if( this != &rhs ) { makeEmpty( ); for( ; !ritr.isPastEnd( ); ritr.advance( ), itr.advance( ) ) insert( ritr.retrieve( ), itr ); } return *this; }
TestLinkedList.cpp : Test program for linked list package #include #include "LinkedList.h" // Simple print method template void printList( const List & theList ) { if( theList.isEmpty( ) ) cout << "Empty list" << endl; else { ListItr itr = theList.first( ); for( ; !itr.isPastEnd( ); itr.advance( ) ) cout << itr.retrieve( ) << " "; } cout << endl;
Master your semester with Scribd main( ) & The New Yorkint Times }
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
{ Special offer for students: Only $4.99/month. List theList; ListItr theItr = theList.zeroth( );
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents Sheet Music
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
for( i = 0; i < 10; i++ ) if( ( i % 2 == 0 ) != ( theList.find( i ).isPastEnd( ) ) ) cout << "Find fails!" << endl; cout << "Finished deletions" << endl; printList( theList ); List list2; list2 = theList; printList( list2 ); return 0; }
Polynomial.cpp : Polynomials /* * This code doesn't really do much, and abstraction is not built in. * Thus, I haven't bothered testing it exhaustively. */ #include #include "vector.h" class Polynomial { enum { MAX_DEGREE = 100 }; friend int main( ); // So I can do a quick test. public: Polynomial( ); void zeroPolynomial( ); Polynomial operator+( const Polynomial & rhs ) const; Polynomial operator*( const Polynomial & rhs ) const; void print( ostream & out ) const;
Master your semester with Scribd private: & The New York Times coeffArray; vector int highPower; Special offer for students: Only $4.99/month. };
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
coeffArray[ i ] = 0; highPower = 0;
Sheet Music
}
Polynomial Polynomial::operator+( const Polynomial & rhs ) const { Polynomial sum; sum.highPower = max( highPower, rhs.highPower ); for( int i = sum.highPower; i >= 0; i-- ) sum.coeffArray[ i ] = coeffArray[ i ] + rhs.coeffArray[ i ]; return sum; }
Polynomial Polynomial::operator*( const Polynomial & rhs ) const { Polynomial product; product.highPower = highPower + rhs.highPower; if( product.highPower > MAX_DEGREE ) cerr << "operator* exceeded MAX_DEGREE" << endl; for( int i = 0; i <= highPower; i++ ) for( int j = 0; j <= rhs.highPower; j++ ) product.coeffArray[ i + j ] += coeffArray[ i ] * rhs.coeffArray[ j ]; return product; } void Polynomial::print( ostream & out ) const { for( int i = highPower; i > 0; i-- ) out << coeffArray[ i ] << "x^" << i << " + "; out << coeffArray[ 0 ] << endl; } ostream & with operator<<( ostream Master your semester Scribd { rhs.print( out ); & The New York Times return out;
Special offer for students: Only $4.99/month. }
& out, const Polynomial & rhs ) Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
CursorList.h : Header file for cursor linked list Sheet Music
#ifndef CursorList_H #define CursorList_H #define List CursorList #include "vector.h" #include "dsexceptions.h" // // // // // // // // // // // position p // // // // // //
LinkedList class using a cursor implementation CONSTRUCTION: with no initializer Access is via LinkedListItr class
******************PUBLIC OPERATIONS********************* boolean isEmpty( ) --> Return true if empty; else false void makeEmpty( ) --> Remove all items ListItr zeroth( ) --> Return position to prior to first ListItr first( ) --> Return first position void insert( x, p ) --> Insert x after current iterator void remove( x ) --> Remove x ListItr find( x ) --> Return position that views x ListItr findPrevious( x ) --> Return position prior to x ******************ERRORS******************************** No special errors
template class ListItr; // Incomplete declaration. template class List { public: List( ); List( const List & rhs ); ~List( );
Master your semester with Scribd & The New York Times
Special offer for students: Only $4.99/month. bool isEmpty( ) const; void makeEmpty( );
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Quest2
1
Download
Magazines
News
Documents
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
: element( theElement ), next( n ) { }
Sheet Music
Object element; int next; friend class List; friend class ListItr; }; const List & operator=( const List & rhs ); private: int header; static vector cursorSpace; static void initializeCursorSpace( ); static int alloc( ); static void free( int p ); friend class ListItr; };
// // // // // // // //
ListItr class; maintains "current position" CONSTRUCTION: Package friendly only, with an int
******************PUBLIC OPERATIONS********************* bool isPastEnd( ) --> True if at valid position in list void advance( ) --> Advance (if not already null) Object retrieve --> Return item in current position
template class ListItr { public: ListItr( ) : current( 0 ) { } Read Free Foron 30this Days Sign up to vote title bool isPastEnd( ) const Useful Not useful { return current == 0; } Cancel anytime. Special offer for students: Only $4.99/month. void advance( ) { if( !isPastEnd( ) ) current =
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
CursorList.cpp : Implementation for cursor linked list Sheet Music
#include "CursorList.h" /** * Routine to initialize the cursorSpace. */ template void List::initializeCursorSpace( ) { static int cursorSpaceIsInitialized = false; if( !cursorSpaceIsInitialized ) { cursorSpace.resize( 100 ); for( int i = 0; i < cursorSpace.size( ); i++ ) cursorSpace[ i ].next = i + 1; cursorSpace[ cursorSpace.size( ) - 1 ].next = 0; cursorSpaceIsInitialized = true; } } /** * Allocate a CursorNode */ template int List::alloc( ) { int p = cursorSpace[ 0 ].next; cursorSpace[ 0 ].next = cursorSpace[ p ].next; return p; } /** * Free a CursorNode */ template Read Free Foron 30this Days Sign up to vote title void List::free( int p ) { Useful anytime. Not useful cursorSpace[ p ].next = cursorSpace[Cancel 0 ].next; Special offer for students: Only $4.99/month. cursorSpace[ 0 ].next = p; }
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Download
Magazines
News
Documents
1.5K views
Sheet Music
Quest2
1
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
* Copy constructor */ template List::List( const List & rhs ) { initializeCursorSpace( ); header = alloc( ); cursorSpace[ header ].next = 0; *this = rhs; } /** * Destroy the list */ template List::~List( ) { makeEmpty( ); free( header ); } /** * Test if the list is logically empty. * return true if empty, false otherwise. */ template bool List::isEmpty( ) const { return cursorSpace[ header ].next == 0; } /** * Make the list logically empty. */ template void List::makeEmpty( ) { while( !isEmpty( ) ) Read Free Foron 30this Days Sign up to vote title remove( first( ).retrieve( ) ); Useful Not useful } Cancel anytime. Special offer for students: Only $4.99/month. /**
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
return ListItr( cursorSpace[ header ].next );
}
Sheet Music
/** * Insert item x after p. */ template void List::insert( const Object & x, const ListItr & p ) { if( p.current != 0 ) { int pos = p.current; int tmp = alloc( ); cursorSpace[ tmp ] = CursorNode( x, cursorSpace[ pos ].next ); cursorSpace[ pos ].next = tmp; } } /** * Return iterator corresponding to the first node containing an item x. * Iterator isPastEnd if item is not found. */ template ListItr List::find( const Object & x ) const { /* 1*/ int itr = cursorSpace[ header ].next; /* 2*/ /* 3*/
while( itr != 0 && cursorSpace[ itr ].element != x ) itr = cursorSpace[ itr ].next;
/* 4*/
return ListItr( itr ); }
Master your semester with Scribd /** * Return iterator prior to & The New York */ Times
Read Free Foron 30this Days Sign up to vote title
the first node containing an item x. Useful Not useful Cancel anytime.
Special offer for students: Only $4.99/month. template ListItr List::findPrevious( const Object & x )
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents Sheet Music
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
void List::remove( const Object & x ) { ListItr p = findPrevious( x ); int pos = p.current; if( cursorSpace[ pos ].next != 0 ) { int tmp = cursorSpace[ pos ].next; cursorSpace[ pos ].next = cursorSpace[ tmp ].next; free ( tmp ); } }
/** * Deep copy of linked lists. */ template const List & List::operator=( const List & rhs ) { ListItr ritr = rhs.first( ); ListItr itr = zeroth( ); if( this != &rhs ) { makeEmpty( ); for( ; !ritr.isPastEnd( ); ritr.advance( ), itr.advance( ) ) insert( ritr.retrieve( ), itr ); } return *this; }
Master your semester: with Scribd Test program for cursor implementation of linked lists TestCursorList.cpp Read Free Foron 30this Days Sign up to vote title & The New York#include Times Useful Not useful #include "CursorList.h" Special offer for students: Only $4.99/month.
Cancel anytime.
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Sheet Music
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
vector::CursorNode> List::cursorSpace; int main( ) { List theList; ListItr theItr = theList.zeroth( ); int i; printList( theList ); for( i = 0; i < 10; i++ ) { theList.insert( i, theItr ); printList( theList ); theItr.advance( ); } for( i = 0; i < 10; i += 2 ) theList.remove( i ); for( i = 0; i < 10; i++ ) if( ( i % 2 == 0 ) != ( theList.find( i ).isPastEnd( ) ) ) cout << "Find fails!" << endl; cout << "Finished deletions" << endl; printList( theList ); return 0; }
StackAr.h : Header file for stack: array version #ifndef STACKAR_H #define STACKAR_H
Master your semester with Scribd & The New York#include Times"vector.h" #include "dsexceptions.h"
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Special offer for students: Only $4.99/month. // Stack class -- array implementation
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents Sheet Music
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
template class Stack { public: explicit Stack( int capacity = 10 ); bool isEmpty( ) const; bool isFull( ) const; const Object & top( ) const; void makeEmpty( ); void pop( ); void push( const Object & x ); Object topAndPop( ); private: vector theArray; int topOfStack; }; #include "StackAr.cpp" #endif
StackAr.cpp : Implementation for stack: array version #include "StackAr.h" /** * Construct the stack. */ template Stack::Stack( int capacity ) : theArray( capacity ) { topOfStack = -1; }
Master your semester Scribd * Test ifwith the stack is logically empty. Read Free Foron 30this Days Sign up to vote title * Return true if empty, false otherwise. & The New York */ Times Useful Not useful /**
template Special offer for students: Only $4.99/month. bool Stack::isEmpty( ) const {
Cancel anytime.
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Download
Magazines
News
Documents
1.5K views
Sheet Music
Quest2
1
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
* Make the stack logically empty. */ template void Stack::makeEmpty( ) { topOfStack = -1; } /** * Get the most recently inserted item in the stack. * Does not alter the stack. * Return the most recently inserted item in the stack. * Exception Underflow if stack is already empty. */ template const Object & Stack::top( ) const { if( isEmpty( ) ) throw Underflow( ); return theArray[ topOfStack ]; } /** * Remove the most recently inserted item from the stack. * Exception Underflow if stack is already empty. */ template void Stack::pop( ) { if( isEmpty( ) ) throw Underflow( ); topOfStack--; } /** * Insert x into the stack, if not already full. * Exception Overflow if stack is already full. */ Read Free Foron 30this Days Sign up to vote title template Useful Not useful void Stack::push( const Object &Cancel x )anytime. Special offer for students: Only $4.99/month. { if( isFull( ) )
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
}
Sheet Music
TestStackAr.cpp : Test program for (array-based) stacks
#include #include "StackAr.h" int main( ) { Stack s; for( int i = 0; i < 10; i++ ) s.push( i ); while( !s.isEmpty( ) ) cout << s.topAndPop( ) << endl; return 0; }
StackLi.h : Header file for stack: list version #ifndef STACKLI_H #define STACKLI_H #include "dsexceptions.h" #include
// For NULL
// Stack class -- linked list implementation // // CONSTRUCTION: with no parameters // // ******************PUBLIC OPERATIONS********************* // void push( x ) --> Insert x // void pop( ) --> Remove most recently inserted ite // Object top( ) --> Return most recently inserted ite Read Free Foron 30this Days Sign up to vote titlerecently // Object topAndPop( ) --> Return and remove most inserted item Not useful Useful Cancel // bool isEmpty( ) --> Return true ifanytime. empty; else false Special offer for students: Only $4.99/month. // bool isFull( ) --> Return true if full; else false // void makeEmpty( ) --> Remove all items
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Quest2
1
Download
Magazines
News
Documents
Sheet Music
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
void makeEmpty( ); void pop( ); void push( const Object & x ); Object topAndPop( ); const Stack & operator=( const Stack & rhs ); private: struct ListNode { Object element; ListNode *next; ListNode( const Object & theElement, ListNode * n = NULL ) : element( theElement ), next( n ) { } }; ListNode *topOfStack; }; #include "StackLi.cpp" #endif
StackLi.cpp : Implementation for stack: list version
#include "StackLi.h" #include /** * Construct the stack. */ template Stack::Stack( ) { topOfStack = NULL; } Special offer for students: Only $4.99/month. /**
Master your semester with Scribd & The New York Times
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
makeEmpty( );
Sheet Music
} /** * Test if the stack is logically full. * Return false always, in this implementation. */ template bool Stack::isFull( ) const { return false; } /** * Test if the stack is logically empty. * Return true if empty, false otherwise. */ template bool Stack::isEmpty( ) const { return topOfStack == NULL; } /** * Make the stack logically empty. */ template void Stack::makeEmpty( ) { while( !isEmpty( ) ) pop( ); } /** * Get the most recently inserted item in the stack. * Return the most recently inserted item in the stack * or throw an exception if empty. */ Read Free Foron 30this Days Sign up to vote title template Useful Not useful const Object & Stack::top( ) const Cancel anytime. Special offer for students: Only $4.99/month. { if( isEmpty( ) )
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents Sheet Music
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
topOfStack = topOfStack->next; delete oldTop; } /** * Return and remove the most recently inserted item * from the stack. */ template Object Stack::topAndPop( ) { Object topItem = top( ); pop( ); return topItem; } /** * Insert x into the stack. */ template void Stack::push( const Object & x ) { topOfStack = new ListNode( x, topOfStack ); } /** * Deep copy. */ template const Stack & Stack:: operator=( const Stack & rhs ) { if( this != &rhs ) { makeEmpty( ); if( rhs.isEmpty( ) ) return *this; Read Free Foron 30this Days Sign up to vote title ListNode *rptr = rhs.topOfStack; Useful Not useful ListNode *ptr = new ListNode( rptr->element ); Cancel anytime. Special offer for students: Only $4.99/month. topOfStack = ptr;
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Sheet Music
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
for( int i = 0; i < 10; i++ ) s.push( i ); s1 = s; cout << "s" << endl; while( !s.isEmpty( ) ) cout << s.topAndPop( ) << endl; cout << endl << "s1" << endl; while( !s1.isEmpty( ) ) cout << s1.topAndPop( ) << endl; return 0; }
QueueAr.h : Header file for queue: array version #ifndef QUEUEAR_H #define QUEUEAR_H #include "vector.h" #include "dsexceptions.h" // Queue class -- array implementation // // CONSTRUCTION: with or without a capacity; default is 10 // // ******************PUBLIC OPERATIONS********************* // void enqueue( x ) --> Insert x // void dequeue( ) --> Return and remove least recently inserted item // Object getFront( ) --> Return least recently inserted item // bool isEmpty( ) --> Return true if empty; else false // bool isFull( ) --> Return true ifFor full; else false Read Free 30this Days Sign up to vote on title // void makeEmpty( ) --> Remove all items Not useful Useful // ******************ERRORS******************************** Cancel anytime. // Overflow and Underflow thrown as needed Special offer for students: Only $4.99/month.
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents
Quest2
1
Download
1.5K views
of 51
vector int int int
Sheet Music
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
theArray; currentSize; front; back;
void increment( int & x ); }; #include "QueueAr.cpp" #endif
QueueAr.cpp : Implementation for queue: array version #include "QueueAr.h" /** * Construct the queue. */ template Queue::Queue( int capacity ) : theArray( capacity ) { makeEmpty( ); } /** * Test if the queue is logically empty. * Return true if empty, false otherwise. */ template bool Queue::isEmpty( ) const { return currentSize == 0; } /** * Test if the queue is logically full. * Return true if full, false otherwise. */ Read Free Foron 30this Days Sign up to vote title template bool Queue::isFull( ) const Useful Not useful Cancel anytime. { Special offer for students: Only $4.99/month. return currentSize == theArray.size( ); }
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
* Return the least recently inserted item in the queue * or throw Underflow if empty. */ template const Object & Queue::getFront( ) const { if( isEmpty( ) ) throw Underflow( ); return theArray[ front ]; }
Sheet Music
/** * Return and remove the least recently inserted item from the queue. * Throw Underflow if empty. */ template Object Queue::dequeue( ) { if( isEmpty( ) ) throw Underflow( ); currentSize--; Object frontItem = theArray[ front ]; increment( front ); return frontItem; } /** * Insert x into the queue. * Throw Overflow if queue is full */ template void Queue::enqueue( const Object & x ) { if( isFull( ) ) throw Overflow( ); increment( back ); Read Free Foron 30this Days Sign up to vote title theArray[ back ] = x; Useful Not useful currentSize++; Cancel anytime. Special offer for students: Only $4.99/month. }
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Quest2
1
Download
Magazines
News
Documents
1.5K views
Sheet Music
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
int main( ) { Queue q; for( int j = 0; j < 5; j++ ) { for( int i = 0; i < 5; i++ ) q.enqueue( i ); while( !q.isEmpty( ) ) cout << q.dequeue( ) << endl; } return 0; }
BinarySearchTree.h : Header file for binary search tree #ifndef BINARY_SEARCH_TREE_H_ #define BINARY_SEARCH_TREE_H_ #include "dsexceptions.h" #include
// For NULL
// Binary node and forward declaration because g++ does // not understand nested classes. template class BinarySearchTree; template class BinaryNode { Comparable element; BinaryNode *left; BinaryNode *right; BinaryNode( const Comparable & theElement, BinaryNode *lt, BinaryNode *rt ) : element( theElement ), left( lt ), right( rt ) { } Read Free Foron 30this Days Sign up to vote title friend class BinarySearchTree; }; Useful Not useful
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
// BinarySearchTree class
Cancel anytime.
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Quest2
1
Download
Magazines
News
Documents
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
template class BinarySearchTree { public: explicit BinarySearchTree( const Comparable & notFound ); BinarySearchTree( const BinarySearchTree & rhs ); ~BinarySearchTree( );
Sheet Music
const Comparable & findMin( ) const; const Comparable & findMax( ) const; const Comparable & find( const Comparable & x ) const; bool isEmpty( ) const; void printTree( ) const; void makeEmpty( ); void insert( const Comparable & x ); void remove( const Comparable & x ); const BinarySearchTree & operator=( const BinarySearchTree & rhs ); private: BinaryNode *root; const Comparable ITEM_NOT_FOUND; const Comparable & elementAt( BinaryNode *t ) const; void insert( const Comparable & x, BinaryNode * & t ) const; void remove( const Comparable & x, BinaryNode * & t ) const;
BinaryNode * findMin( BinaryNode *t ) const;
BinaryNode * findMax( BinaryNode *t ) const;
BinaryNode Comparable & x, Master your semester with Scribd * find( const BinaryNode *t ) const; Read Free Foron 30this Days Sign up to vote title void makeEmpty( BinaryNode * & t ) const; & The New York Times useful Useful *t )Notconst; void printTree( BinaryNode Cancel anytime.
Special offer for students: Only $4.99/month. BinaryNode * clone( BinaryNode *t ) const;
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Download
Magazines
News
Documents
1.5K views
Sheet Music
Quest2
1
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
/** * Construct the tree. */ template BinarySearchTree::BinarySearchTree( const Comparable & notFound ) : root( NULL ), ITEM_NOT_FOUND( notFound ) { }
/** * Copy constructor. */ template BinarySearchTree:: BinarySearchTree( const BinarySearchTree & rhs ) : root( NULL ), ITEM_NOT_FOUND( rhs.ITEM_NOT_FOUND ) { *this = rhs; } /** * Destructor for the tree. */ template BinarySearchTree::~BinarySearchTree( ) { makeEmpty( ); } /** * Insert x into the tree; duplicates are ignored. */ template void BinarySearchTree::insert( const Comparable & x
) Master your semester with Scribd { insert( x, root ); & The New York} Times
Special offer for students: Only $4.99/month. /**
Read Free Foron 30this Days Sign up to vote title
Not useful Cancel anytime.
Useful
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
const Comparable & BinarySearchTree::findMin( )
Sheet Music
const { return elementAt( findMin( root ) ); } /** * Find the largest item in the tree. * Return the largest item of ITEM_NOT_FOUND if empty. */ template const Comparable & BinarySearchTree::findMax( ) const { return elementAt( findMax( root ) ); } /** * Find item x in the tree. * Return the matching item or ITEM_NOT_FOUND if not found. */ template const Comparable & BinarySearchTree:: find( const Comparable & x ) const { return elementAt( find( x, root ) ); } /** * Make the tree logically empty. */ template void BinarySearchTree::makeEmpty( ) { makeEmpty( root ); }
Master your semester with Scribd /** Read Free Foron 30this Days Sign up to vote title * Test if the tree is logically empty. & The New York *Times Useful Not useful Return true if empty, false otherwise. Special offer for students: Only $4.99/month. */ template
Cancel anytime.
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
}
Sheet Music
/** * Deep copy. */ template const BinarySearchTree & BinarySearchTree:: operator=( const BinarySearchTree & rhs ) { if( this != &rhs ) { makeEmpty( ); root = clone( rhs.root ); } return *this; } /** * Internal method to get element field in node t. * Return the element field or ITEM_NOT_FOUND if t is NULL. */ template const Comparable & BinarySearchTree:: elementAt( BinaryNode *t ) const { if( t == NULL ) return ITEM_NOT_FOUND; else return t->element; } /** * Internal method to insert into a subtree. * x is the item to insert. * t is the node that roots the tree. * Set the new root. */ Read Free Foron 30this Days Sign up to vote title template Useful Not useful void BinarySearchTree:: Cancel anytime. Special offer for students: Only $4.99/month. insert( const Comparable & x, BinaryNode * & t ) const
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Quest2
1
Download
Magazines
News
Documents
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
* Set the new root. */ template void BinarySearchTree:: remove( const Comparable & x, BinaryNode * & t )
Sheet Music
const { if( t == NULL ) return; // Item not found; do nothing if( x < t->element ) remove( x, t->left ); else if( t->element < x ) remove( x, t->right ); else if( t->left != NULL && t->right != NULL ) // Two children { t->element = findMin( t->right )->element; remove( t->element, t->right ); } else { BinaryNode *oldNode = t; t = ( t->left != NULL ) ? t->left : t->right; delete oldNode; } } /** * Internal method to find the smallest item in a subtree t. * Return node containing the smallest item. */ template BinaryNode * BinarySearchTree::findMin( BinaryNode *t ) const { if( t == NULL ) return NULL; Read Free Foron 30this Days Sign up to vote title if( t->left == NULL ) Useful Not useful return t; Cancel anytime. Special offer for students: Only $4.99/month. return findMin( t->left ); }
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Download
Magazines
News
Documents
Sheet Music
Quest2
1
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
/** * Internal method to find an item in a subtree. * x is item to search for. * t is the node that roots the tree. * Return node containing the matched item. */ template BinaryNode * BinarySearchTree:: find( const Comparable & x, BinaryNode *t ) const { if( t == NULL ) return NULL; else if( x < t->element ) return find( x, t->left ); else if( t->element < x ) return find( x, t->right ); else return t; // Match } /****** NONRECURSIVE VERSION************************* template BinaryNode * BinarySearchTree:: find( const Comparable & x, BinaryNode *t ) const { while( t != NULL ) if( x < t->element ) t = t->left; else if( t->element < x ) t = t->right; else return t; // Match return NULL;
// No match
} Master your semester with Scribd *****************************************************/ Read Free Foron 30this Days Sign up to vote title & The New York/** Times Useful Not useful Cancel anytime.
Special offer for students: Only $4.99/month. * Internal method to make subtree empty. */
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Quest2
1
Download
Magazines
News
Documents
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
* Internal method to print a subtree rooted at t in sorted
Sheet Music
order. */ template void BinarySearchTree::printTree( BinaryNode *t ) const { if( t != NULL ) { printTree( t->left ); cout << t->element << endl; printTree( t->right ); } } /** * Internal method to clone subtree. */ template BinaryNode * BinarySearchTree::clone( BinaryNode * t ) const { if( t == NULL ) return NULL; else return new BinaryNode( t->element, clone( t->left ), clone( t->right ) ); }
TestBinarySearchTree.cpp : Test program for binary search tree #include #include "BinarySearchTree.h"
Master your semester Scribd int main( with ) { const int ITEM_NOT_FOUND & The New York Times // Test program
Read Free Foron 30this Days Sign up to vote title
= -9999; Useful Not useful Cancel anytime. BinarySearchTree t( ITEM_NOT_FOUND ); Special offer for students: Only $4.99/month. int NUMS = 4000; const int GAP 37;
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
1
Download
Magazines
News
Documents
Quest2
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
cout << "FindMin or FindMax error!" << endl;
Sheet Music
for( i = 2; i < NUMS; i+=2 ) if( t.find( i ) != i ) cout << "Find error1!" << endl; for( i = 1; i < NUMS; i+=2 ) { if( t.find( i ) != ITEM_NOT_FOUND ) cout << "Find error2!" << endl; } BinarySearchTree t2( ITEM_NOT_FOUND ); t2 = t; for( i = 2; i < NUMS; i+=2 ) if( t2.find( i ) != i ) cout << "Find error1!" << endl; for( i = 1; i < NUMS; i+=2 ) { if( t2.find( i ) != ITEM_NOT_FOUND ) cout << "Find error2!" << endl; }
return 0; }
AvlTree.h : Header file for AVL tree #ifndef AVL_TREE_H_ #define AVL_TREE_H_
// Node and forward declaration because g++ does // not understand nested classes. template Read Free Foron 30this Days Sign up to vote title class AvlTree; Useful Not useful Cancel anytime. template Special offer for students: Only $4.99/month. class AvlNode {
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
1.5K views
0
Sign In
Upload
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Download
Magazines
News
Documents
Sheet Music
Quest2
1
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
// AvlTree class // // CONSTRUCTION: with ITEM_NOT_FOUND object used to signal failed finds // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert x // void remove( x ) --> Remove x (unimplemented) // Comparable find( x ) --> Return item that matches x // Comparable findMin( ) --> Return smallest item // Comparable findMax( ) --> Return largest item // boolean isEmpty( ) --> Return true if empty; else false // void makeEmpty( ) --> Remove all items // void printTree( ) --> Print tree in sorted order template class AvlTree { public: explicit AvlTree( const Comparable & notFound ); AvlTree( const AvlTree & rhs ); ~AvlTree( ); const Comparable & findMin( ) const; const Comparable & findMax( ) const; const Comparable & find( const Comparable & x ) const; bool isEmpty( ) const; void printTree( ) const; void makeEmpty( ); void insert( const Comparable & x ); void remove( const Comparable & x ); const AvlTree & operator=( const AvlTree & rhs ); private:with Scribd Master your semester AvlNode *root; Read Free Foron 30this Days Sign up to vote title const Comparable ITEM_NOT_FOUND; & The New York Times Useful Not useful Cancel anytime.
Special offer for students: Only $4.99/month. const Comparable & elementAt( AvlNode *t ) const;
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Magazines
News
Documents Sheet Music
Quest2
1
Download
1.5K views
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
int max( int lhs, int rhs ) const; void rotateWithLeftChild( AvlNode * & k2 ) const; void rotateWithRightChild( AvlNode * & k1 ) const; void doubleWithLeftChild( AvlNode * & k3 ) const; void doubleWithRightChild( AvlNode * & k1 ) const; }; #include "AvlTree.cpp" #endif
AvlTree.cpp : Implementation for AVL tree #include "AvlTree.h" #include /** * Implements an unbalanced Avl search tree. * Note that all "matching" is based on the compares method. * @author Mark Allen Weiss */ /** * Construct the tree. */ template AvlTree::AvlTree( const Comparable & notFound ) : ITEM_NOT_FOUND( notFound ), root( NULL ) { } /** * Copy constructor. */ template AvlTree::AvlTree( const AvlTree & rhs ) Read Free Foron 30this Days Sign up to vote title : ITEM_NOT_FOUND( rhs.ITEM_NOT_FOUND root( NULL ) Useful Not useful ), Cancel anytime. { Special offer for students: Only $4.99/month. *this = rhs; }
Master your semester with Scribd & The New York Times
Home
Saved
Bestsellers
Books
Audiobooks
Magazines
News
Documents
Sheet Music
Master your semester with Scribd & The New York Times Special offer for students: Only $4.99/month.
Upload
Sign In
Read Free For 30 Days Cancel anytime.
Join
Search
Home
Saved
0
Upload
Sign In
Join
RELATED TITLES
0
Source Code for Data Structures and Algorithm Analysis in c
Uploaded by venkat05091990
Bestsellers
Books
Audiobooks
Save
Embed
Share
Print
Download
Magazines
News
Documents
1.5K views
Sheet Music
Quest2
1
of 51
THE APPLICATION OF
Useful Programs in C With Aim and
Search document
void AvlTree::insert( const Comparable & x ) { insert( x, root ); } /** * Remove x from the tree. Nothing is done if x is not found. */ template void AvlTree::remove( const Comparable & x ) { cout << "Sorry, remove unimplemented; " << x << " still present" << endl; } /** * Find the smallest item in the tree. * Return smallest item or ITEM_NOT_FOUND if empty. */ template const Comparable & AvlTree