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; }
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.
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 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
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>
This program using the selection, insertion, and bubble sorts. The program needs to be able to do the following:
1. Create an array of 1000 population records when the array object is instantiated. Call it unSorted.
2.Open the file called "Population.csv" (on the portal) and invoke a function that loads the population data into the array.
3.Create a second array of 1000 elements that will be used to sort the data using the different algorithms. Name is sortedArray.
4.Write a function that will copy unSorted into sortedArray and execute that function.
5.Using a function, display the unsorted array.
6.Invoke the insertionSort () function that will sort the sortedArray using the insertion sort algorithm. Sort the population data on the rank field in ascending order. Alternatively, you can sort in descending order on population.
7.Using the display function, display sortedArray.
8.Display the number of iterations it took to do the sort using this algorithm.
9.Repeat steps 4-8 for the selection and bubble sort algorithms.
Here is my code so far:
Code: #include <iostream> #include <iomanip> #include <fstream> using namespace std; void loadArray (int unSorted[], int s); void displayArray (const int num [], int size);
[Code] .....
Here is a few lines from the Population.csv file contents:
I'm not sure how to load the data from the file into the array properly, I attempted this. I also don't know how to copy the unSorted into sortedArray.
HelI have been tasked with creating a program which (1) takes in integer values from a user (until the user enters -1) and inputs these values into a linked list. This (2)original list is then to be printed out. The program then uses the algorithm "bubble sort" to (3)order the list in descending order before finally printing it out again.
I have managed to do this but I kind of cheated since I do not quite understand how to manipulate a linked list. What did was I took the values in the linked list and transferred them into an array and then did bubble sort on that array.how to do bubble sort on a linked list as well as how to print a linked list.
Code:
#include<stdio.h>#include<stdlib.h> typedef struct node { int info; struct node *link;
This program is sorting a randomized array of integers using the bubblesort algorithm.
I am trying to modify n correct the source code,so that the swapping of two values will be done by a function called swap values() by using call-by-reference but function should have as arguments only the two array elements that must be exchanged. (Note: do not pass the whole array to the function!) .We consider an array with the first element containing the number of elements in the array, followed by 10 randomly initialized integers (elements).
The code must sort the 10 elements in ascending order.
Compile: g++ -Wall sorting.cpp -o sorting */ #include <iostream> #include <stdlib.h> using namespace std; int main() { const int SIZE=10;
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.
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.
Code: # include <iostream> using namespace std; int main() { const int SIZE1 = 3; const int SIZE2 = 8; int arr [SIZE1][SIZE2] = { { 105, 102, 107, 103, 106, 100, 104, 101 },
I have this program thats supposed to add a number to all of its precedents. so if the input was 5, it would add 5+4+3+2+1 and give 15. I know i can implement this in a billion different way and it wouldnt be much of a challenge, but im really confused as to why this isnt working. It gives a large negative number when i run it.
#include <iostream> using namespace std; int main() { int b; cout<<"Enter a number, ill return that number plus every number below it: ";
I have this code(homework) i've been working on for several days i couldn't fix this error.
Question is: to write a sort program in c . Ineed to ask user for how many numbers to be sorted(n) ask again for values. The approach of sort is this:
1- store n in temporary var (temp) 2- search for largest number in array (0 until temp-1) 3- switch the fied that store largest with field indexed by (temp-1) 4- temp-- (decrement) 5- repeat steps 2 to 4 until temp is 1
the program then prints the numbers of array on screen in one line. I also should use a function getMax(int *list , int n) that determines largest value and returns its location in that array
list : is the array n: number of elements
Code: #include<stdio.h> int getMax(int *list, int n); //definition of getMax function int main(void) { int n,i;
[Code] .....
so i tried to sort this array
Code: input 2 7 9 4 3 1 6 5 The out put should be : 9 7 6 5 4 3 2 1 instead it prints : 7 9 2 4 3 1 6