Help please my program does not 'cout' results int partition(int a[], int f, int r) { int pivot = a[f]; // pivot is the first element int small = f; // small pointer from the left int large = r; // large pointer from the right while (small <= large) { //until they cross // until the small and large cross // loop for finding out-of-place pairs and swap them // if both are bad (and not crossed yet), swap and then move // if a[small] is OK, move small // if a[large] is OK, move large // TODO: ** while (small <= large && a[small] < pivot) { //you will be checking a[small] and a[large] against pivot small++; } while (small <= large && a[large] >= pivot) { // TODO:**// return the partition point where // those smaller than pivot are before what is returned // there is a special cases (small is at the beginning) large--; } if (small <= large) { swap(a[small], a[large]); } } return small; } //and a regular case //end of while int main() { int x; // number of elements int nums[10]; cout << "How many elements? (must be less than 10) "; cin >> x; cout << "Enter elements one per line.." << endl; for (int i = 0; i < x; i++) { cin >> nums[i]; } // the pivot is always the first element cout << "Ok the pivot is " << nums[0] << endl; int part = partition(nums, 0, x-1); cout << "Results..." << endl; // display up to the partition without endl for (int i = 0; i < part; i++) cout << nums[i]; cout << "|"; // display from the partition on.. without endl for (int i = part; i < x; i++) cout << nums[i]; cout << endl; }
Help please my program does not 'cout' results int partition(int a[], int f, int r) { int pivot = a[f]; // pivot is the first element int small = f; // small pointer from the left int large = r; // large pointer from the right while (small <= large) { //until they cross // until the small and large cross // loop for finding out-of-place pairs and swap them // if both are bad (and not crossed yet), swap and then move // if a[small] is OK, move small // if a[large] is OK, move large // TODO: ** while (small <= large && a[small] < pivot) { //you will be checking a[small] and a[large] against pivot small++; } while (small <= large && a[large] >= pivot) { // TODO:**// return the partition point where // those smaller than pivot are before what is returned // there is a special cases (small is at the beginning) large--; } if (small <= large) { swap(a[small], a[large]); } } return small; } //and a regular case //end of while int main() { int x; // number of elements int nums[10]; cout << "How many elements? (must be less than 10) "; cin >> x; cout << "Enter elements one per line.." << endl; for (int i = 0; i < x; i++) { cin >> nums[i]; } // the pivot is always the first element cout << "Ok the pivot is " << nums[0] << endl; int part = partition(nums, 0, x-1); cout << "Results..." << endl; // display up to the partition without endl for (int i = 0; i < part; i++) cout << nums[i]; cout << "|"; // display from the partition on.. without endl for (int i = part; i < x; i++) cout << nums[i]; cout << endl; }
Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 12PE
Related questions
Question
Help please my program does not 'cout' results
int partition(int a[], int f, int r) {
int pivot = a[f]; // pivot is the first element
int small = f; // small pointer from the left
int large = r; // large pointer from the right
while (small <= large) { //until they cross // until the small and large cross
// loop for finding out-of-place pairs and swap them
// if both are bad (and not crossed yet), swap and then move
// if a[small] is OK, move small
// if a[large] is OK, move large
// TODO: **
while (small <= large && a[small] < pivot) { //you will be checking a[small] and a[large] against pivot
small++;
}
while (small <= large && a[large] >= pivot) { // TODO:**// return the partition point where
// those smaller than pivot are before what is returned
// there is a special cases (small is at the beginning)
large--;
}
if (small <= large) {
swap(a[small], a[large]);
}
}
return small;
}
//and a regular case
//end of while
int main()
{
int x; // number of elements
int nums[10];
cout << "How many elements? (must be less than 10) ";
cin >> x;
cout << "Enter elements one per line.." << endl;
for (int i = 0; i < x; i++)
{ cin >> nums[i]; }
// the pivot is always the first element
cout << "Ok the pivot is " << nums[0] << endl;
int part = partition(nums, 0, x-1);
cout << "Results..." << endl;
// display up to the partition without endl
for (int i = 0; i < part; i++)
cout << nums[i];
cout << "|";
// display from the partition on.. without endl
for (int i = part; i < x; i++)
cout << nums[i];
cout << endl;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT