Beispiel #1
0
        const List<Object> & List<Object>::operator=( const List<Object> & rhs )
        {
            if( this != &rhs )
            {
                makeEmpty( );

                ListItr<Object> ritr = rhs.first( );
                ListItr<Object> itr = zeroth( );
                for( ; !ritr.isPastEnd( ); ritr.advance( ), itr.advance( ) )
                    insert( ritr.retrieve( ), itr );
            }
            return *this;
        }
Beispiel #2
0
ostream & operator<<( ostream & out, const WordEntry & rhs )
{
    out << rhs.word << ": ";

    if( rhs.lines != NULL && !rhs.lines->isEmpty( ) )
    {
        ListItr<int> itr = rhs.lines->first( );
        out << '\t' << itr.retrieve( );
        for( itr.advance( ); !itr.isPastEnd( ); itr.advance( ) )
            out << ", " << itr.retrieve( );
    }
    return out;
}
        int main( )
        {
            List<int>    theList;
            ListItr<int> 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 );

            List<int> list2;
            list2 = theList;
            printList( list2 );

            return 0;
        }
//template <class Object>
void RunList(ifstream& stream){
   char iord;
   int number;
   
   //string dummy;
   //getline(stream, dummy);
  
   char dummy[256];
   stream.getline(dummy, 256); 
   
   List<int> list;
   ListItr<int> listItr = list.zeroth();
   
   while(stream >> iord >> number){
      if(iord == 'i'){
      list.insert(number, listItr);
      listItr.advance();
      //cout << "Inserted " << number << endl;
      }
      
      else /*if(iord == 'd')*/{
      list.remove(number);
      //cout << "Deleted " << number << endl;
      }
   }
   
   stream.clear();
   stream.seekg(0, ios::beg); 
}
Beispiel #5
0
void Graph::unweighted( const string & startName )
{
    clearAll( );

    const MapEntry & match = vertexMap.find( MapEntry( startName ) );
    if( match == ITEM_NOT_FOUND )
    {
        cout << startName << " is not a vertex in this graph" << endl;
        return;
    }

    Vertex *start = match.storedVertex;
    Queue<Vertex *> q( numVertices );
    q.enqueue( start ); start->dist = 0;

    while( !q.isEmpty( ) )
    {
        Vertex *v = q.dequeue( );

        ListItr<Vertex *> itr;
        for( itr = v->adj.first( ); !itr.isPastEnd( ); itr.advance( ) )
        {
            Vertex *w = itr.retrieve( );
            if( w->dist == INFINITY )
            {
                w->dist = v->dist + 1;
                w->path = v;
                q.enqueue( w );
            }
        }
    }
}
        void printList( const List<Object> & theList )
        {
            if( theList.isEmpty( ) )
                cout << "Empty list" << endl;
            else
            {
                ListItr<Object> itr = theList.first( );
                for( ; !itr.isPastEnd( ); itr.advance( ) )
                    cout << itr.retrieve( ) << " ";
            }

            cout << endl;
        }
Beispiel #7
0
Graph::~Graph( )
{
    ListItr<Vertex *> itr;
    for( itr = allVertices.first( ); !itr.isPastEnd( ); itr.advance( ) )
        delete itr.retrieve( );
}
Beispiel #8
0
void Graph::clearAll( )
{
    ListItr<Vertex *> itr;
    for( itr = allVertices.first( ); !itr.isPastEnd( ); itr.advance( ) )
        itr.retrieve( )->reset( );
}
void SongSearch::query(const Request &request, Song answer[], int *answerCount)
{
	int counter = 0; 
	if(request.type == 0){
		 Song *temp; 
		 for(int i = 0; i < titles.size() ; i++){
		 	if( titles[i] != NULL && strstr(titles[i]->common, request.criteria) != NULL){
				for( ListItr <Song *> itr  = titles[i]->list->first(); !itr.isPastEnd(); itr.advance()){
				    temp = (Song *) itr.retrieve();
				    //cout << temp->title << endl; 
		  			copy(answer[counter], temp); 
		  			counter++; 
				}
		 	}
		}
		*answerCount = counter; 
	}   
	else if(request.type == 1){
  		const holdlink* link = linearprobingtitle->find(request.criteria); 
  		Song *temp;
  		for( ListItr <Song *>itr  = link->list->first(); !itr.isPastEnd(); itr.advance()){
  	    	temp = (Song *) itr.retrieve();
  	    	copy(answer[counter], temp); 
  	    	counter++; 
  		}
  	*answerCount = counter; 
    }
  	else if(request.type == 2){
  		const holdlink* link = linearprobingartist->find(request.criteria); 
  		Song *temp;
  		for( ListItr <Song *> itr  = link->list->first(); !itr.isPastEnd(); itr.advance()){
  	    	temp = (Song *) itr.retrieve();
  	    	copy(answer[counter], temp); 
  	    	counter++; 
  		}
  		*answerCount = counter; 
  	}   
  	else if(request.type == 3){ //WORKS 
		*answerCount = 0;   
			for(int i = 0; i < songCount; i++){
			   if(strcmp(songs[i]->ID, request.criteria) == 0 ){
			   		copy(answer[*answerCount], songs[i]); 
					(*answerCount)++;
			   		for(int j = i+1; j < songCount; j++){
			   			if(strcmp(songs[j]->ID, request.criteria2) == 0){
				   			while(strcmp(songs[j]->ID, request.criteria2) == 0){
						   		copy(answer[*answerCount], songs[j]); 
					   			(*answerCount)++;
				   				j++; 
				   			}
				   			return; 
			   			}
			   			else{
							copy(answer[*answerCount], songs[j]); 
				   			(*answerCount)++;
			   			}
			   		}	
				}
		    }
	}
    else if (request.type == 4){
  		const holdlink* link = linearprobingalbum->find(request.criteria); 
  		Song *temp;
  		for( ListItr <Song *> itr  = link->list->first(); !itr.isPastEnd(); itr.advance()){
  	    	temp = (Song *) itr.retrieve();
  	    	copy(answer[counter], temp); 
  	    	counter++; 
  		}
  		*answerCount = counter; 
    }
	
	return;  
}