so my program reads a file type which looks like this...
Michelle 71
Marcie 99
David 42
Rebecca 83
Jonathan 79
Matthew 77
Rose 7
Melanie 75
Kimberly 73
Roger 74
Scott 76
Bradley 77
Drextell 10
Heidi 70
Alan 68
Pearl 13
Jeanne 43
Heber 55
Here is whats in the header of the class
class StudentStat {
private:
int Size;
[Code].....
So as of right now the names are stored in a Names string array and the scores are saved in a Score int array. So my question is where do I begin with my bubble sort? I need it to put the scores in descending order so from greatest score to lowest but I need the Names in the string array to still be connected to the number from the list. Never done a bubble sort before so not sure where to begin.
I'm stuck again on a homework problem. I enter 9 8 7 6 5 4 3 2 1 in to the program when it asks me to. I print out the array (just before the bubble sort routine) and I get the numbers in descending order just as expected. So going into bubble sort routine, the numbers are correct.
I should get 1 2 3 4 5 6 7 8 9 as output.
But I get 1 2 3 4 4 5 6 7 8
Code: #include <stdio.h> #include <stdlib.h> int main() { int max_size = 20; // max size of array of numbers int numbers[max_size]; // array for numbers
This compiles fine but when I run the .exe for the first time an error message comes up saying program has stopped working. If I run the program again without recompiling it seems to work as expected.
I have to put these numbers in ascending and descending order . The interesting point of the function is that sortMe does NOT re-arrange elements in the array; instead, it uses a second array, an array of indexes for the elements in the original array and then sortMe sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes. I'm not sure why the function is working, even though I called it in main.
#include <iostream> #include <fstream> #include <string> using namespace std; void sortMe(int array[], int sortedIndexes[], int size, char mode); char option; const int SIZE = 5;
What kind of code should i use for sorting numbers in both ascending and descending order? I don't know how to use bubble sorting either, is there another easy way to sort this out?
You will write a program that uses a multidimensional array having 3 rows and 8 columns and sorts each of the rows using both a bubble sort and a selection sort.
You must declare the array inside of main. You will have a for loop containing the calls to bubbleSort and selectionSort. You need to pass into function bubbleSort and selectionSort the following: 1) each column of the multidimensional array, 2) the size of the column, and 3) a particular row number of the multidimensional array to be used for printing out the "pass" shown on the following pages.
I keep getting an error that the identifier for bubbleSort and selectionSort is not found. (Error C3861) Also, I feel like I'm missing something in int main() to get it to sort properly.
# include <iostream> using namespace std; int main() {
i'm trying to fill an array with random numbers and then sort them via bubblesort. it seems to work so far. the problem is, that i seem to get the same numbers for the same input. somehow the randomness isn't working.
Code:
#include <stdio.h> #include <stdlib.h> int main() { int a, b, c, d, e, f; }
Design a C++ Program to implement the following functions:
a.)the function for bubble sorting : int bubblesort(int*a,int size). b.)the function for merge sorting : int mergesort(int*a,int size). c.)the function for generating array of random elements: int generate(int*a,int size) which calls the function rand() in c++. d.)Test both bubble sorting and merge sorting with 10,100,1000,10000,100000 and 1000000,4000000 integers.
The integers are from the array generated by part c).calculate the time spent in calling each sorting.you may use a function in <time.h>to get the current time. Draw curves to compare the speed performance between the two functions. The merge sorting algorithm implementation must use recursion. you are expected to define a global array for holding result from merging two arrays.otherwise,it may cause a lot extra money in recursion.
Hint 1:use the following format to calculate the time cost for bubble sort.
{…….. Time1=Get the current time(call a function in <time.h>); Bbblesort(….) Tme2=Get the current time(call a function in <time.h>); Time_cost=the difference between time 1 and tim2; ……. } Print your program and test results
I'll make a program that consists of "sorting and searching." To cope with the task, it should contain this: Create a field containing 50 random numbers, sort them by a method sort according to Bubble sort and then out the field before and after sorting. [URL]
Been working on this program for a while. It's currently broken in several parts but it at least reads and stores the data into the arrays correctly. The problem is writing the sort function and the swap function. The other problem is writing both of these to keep the correct ages with the correct names.
/* Write a program to allow the user to enter up to ten people with their age. The names will be a full name consisting of a last, possibly a middle initial, and a first name. The full name will be no longer than 40 characters in length. The full will be stored in an array of strings, a two dimensioned array of characters. The ages will be stored in an array of integers. Manage the arrays as parallel arrays. Data entry will be from the keyboard and will read the full name followed by the age. Data entry will terminate when the arrays are full or when nothing is entered for the full name. Use a subroutine to enter the data and pass the arrays to the subroutine, do not use global arrays. Once the data is completely entered, use another subroutine to print out the arrays to the screen. Then use a subroutine to sort the data on the full names, ascending order. Reuse the print subroutine and print the sorted data out to the screen. Write another subroutine which sorts the data on age as the primary sort and full name as the secondary sort. Finally reuse the print subroutine to print the data to the screen. The main program will call the data entry function, followed by the print function, the name sort function, the print function, the age sort function and finally the print function. All data will be passed to the functions, no global data. */
Ive written a long program that should be a bubble sort , unfortunately I cant use loops ...is there any way i can shorten this and make it indeed a bubble sort? Its sorting atm but its not entirely correct.
I'm trying to apply a bubble sort on a linked list. It works in the first traversal, but then after the code cPtr = nPtr;, it inputs repeated digits at the end of the (semi-sorted) linked lists.
I am trying to sort an array of strings but when I pass it through my bubbleSort function, it gives me a segmentation fault. By print checking, I know that there are strings in the array "f" but it doesn't get sorted.
Note: The file I am putting into this program is a text file with 1000 lines
# include <stdio.h> # include <stdlib.h> # include <string.h>