Go Back   Flash Flash Revolution > General Discussion > Critical Thinking > Homework & Help
Register FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 07-18-2016, 03:37 PM   #1
iCeCuBEz v2
XFD
FFR Veteran
 
iCeCuBEz v2's Avatar
 
Join Date: Mar 2008
Location: Connecticut
Age: 33
Posts: 4,924
Default programming question

My assignment is to use this model bubblesort program.

It currently is set up to bubble sort integers but for my assignment I need to bubble sort an array of characters.

How do I modify the code so that it can take an array of characters instead of integers? I've been pulling my hair out for hours trying to figure this out and I've pretty much given up.

I suck at programming I hate it and I'm pissed I have to take this class.

here's the code

#include <iostream>
using namespace std;
void input(int ulist[], int &numberOfElements);
void Bubblesort(int ulist[], int slist[], int numberOfElements);
void print(int list[], int numberOfElements);


const int MAX_SIZE = 10;
void main()
{
int numberOfElements;
int ulist[MAX_SIZE], slist[MAX_SIZE];
input(ulist, numberOfElements);
cout << "Unsorted";
print(ulist, numberOfElements);
cout << "Sorted";
Bubblesort(ulist, slist, numberOfElements);
print(slist, numberOfElements);
system("pause");
}
void input(int ulist[], int& numberOfElements)
{
int i = 0, value;
cout << "enter value : \n";
cin >> value;

while (i < MAX_SIZE && value != -999)
{
ulist[i] = value;
i++;
if (i<MAX_SIZE)
{
cin >> value;
}
}
numberOfElements = i;
}
void Bubblesort(int unlist[], int sortlist[], int numberOfElements)
{
int temp;
for (int i = 0; i < numberOfElements; i++)
sortlist[i] = unlist[i];

for (int i = 0; i < numberOfElements; i++)
{
for (int j = 0; j<numberOfElements - 1; j++)
{
if (sortlist[j]>sortlist[j + 1])
{
temp = sortlist[j];
sortlist[j] = sortlist[j + 1];
sortlist[j + 1] = temp;
}
}
}
}
void print(int list[], int numberOfElements)
{
int sum = 0;
cout << " list of numbers are : \n";
for (int i = 0; i < numberOfElements; ++i)
{
cout << list[i] << '\n';
sum = sum + list[i];
}

double average = (double)sum / (double)numberOfElements;
cout << "\n\n";
cout << "Average is " << average << "\n";
}
__________________
I bring my math homework to church. It helps me find a higher power.

Dennis, Nell, Edna, Leon, Nedra, Anita, Rolf, Nora, Alice, Carol, Leo, Jane, Reed, Dena, Dale, Basil, Rae, Penny, Lana, Dave, Denny, Lena, Ida, Bernadette, Ben, Ray, Lila, Nina, Jo, Ira, Mara, Sara, Mario, Jan, Ina, Lily, Arne, Bette, Dan, Reba, Diane, Lynn, Ed, Eva, Dana, Lynne, Pearl, Isabel, Ada, Ned, Dee, Rena, Joel, Lora, Cecil, Aaron, Flora, Tina, Arden, Noel, and Ellen sinned.
iCeCuBEz v2 is offline   Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 05:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution