Ejemplo n.º 1
0
// Needed for quicksort; partitions the part of the array between the first two params
// by moving everything less than the third param before the pivot, and those greater
// after it, and returns the final position of the pivot element
long partition(long left, long right, long pivotIndex) {
	// Store rank value (what we're sorting by) at the pivot point
	long pivRank = ranks[pivotIndex];
	
	// Move pivots to the end of their array
	swapLong(ranks, pivotIndex, right);
	swapChar(sentences, pivotIndex, right);
	
	// Move things around based on how they compare to the pivot point
	long storeIndex = left;
	long i;
	for (i = left; i < right ;i++) {
		if (ranks[i] > pivRank) {
			swapLong(ranks, i, storeIndex);
			swapChar(sentences, i, storeIndex);
			
			storeIndex++;
		}
	}
	
	// Move pivots to their final places
	swapLong(ranks, storeIndex, right);
	swapChar(sentences, storeIndex, right);
	
	return storeIndex;
}
Ejemplo n.º 2
0
Archivo: b115.c Proyecto: gsrr/Programs
void reverseStr(char str[])
{
        int len = strlen(str);
        int i;
        for( i = 0 ; i < len/2; i++ )
        {
                swapChar(str, i, len - 1 - i);
        }
}
Ejemplo n.º 3
0
main()
{
    char a, b;

    printf("enter a ");
    scanf(" %c", &a);
    printf("enter b ");
    scanf(" %c", &b);
    printf("Before: a = %c and b = %c\n", a, b);
    swapChar(&a,&b);
    printf("After:  a = %c and b = %c\n", a, b);
    return 0;
}
 string reverseVowels(string s) {
     
     int lo = -1,hi = s.length();
     while(lo<hi){
         if(isVowel(s[++lo])){
             while(lo<hi&&!isVowel(s[--hi]));
             s = swapChar(s,lo,hi);
             
         }
     }
     return s;
     
     
 }