Thread: Why am I missing the first element????

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    85

    Why am I missing the first element????

    When sorting....Everything is sorted except the firts element BUT WHY amd HOW DO I FIX??????
    Code:
    int partition(vector<string>& word_vector, int start, int stop)
    {
       string x;
       int i,j;
    
       x = word_vector[stop];
       i = start-1;
       for(j = start; j<= stop - 1; j++)
       {
       	cout << "Start: " << start << endl;
       	if (strcmp(word_vector[j].c_str(),x.c_str())<=0)
    	{
       		i = i + 1;
       		swap(word_vector[i],word_vector[j]);
    	}
       }
       swap(word_vector[i+1],word_vector[stop]);
       return i;
    
    }
    
    void quicksort(vector<string>& word_vector, int start, int stop) 
    {
       int pivot;
       if(start < stop)
       {
       	pivot = partition(word_vector, start, stop);
       	quicksort(word_vector, start, pivot-1);
       	quicksort(word_vector, pivot+1, stop); 
       }
    }

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Include a swap() function?

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    HUH where

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    for anyone who would like to know I figured it out... Simply return i+1 instead of i

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM