Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

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
Check Mark
Knowledge Booster
Background pattern image
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
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education