C/C++ :: Bubble Sort And Selection Sort?

Feb 19, 2014

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()
{

[Code].....

View 14 Replies


ADVERTISEMENT

C++ :: Sorting With Selection / Insertion And Bubble Sort

May 4, 2014

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:

Code:
Alabama,Baldwin County,140415,389
Alabama,Blount County,51024,908
Alabama,Calhoun County,112249,477
Alabama,Colbert County,54984,858
Alabama,Cullman County,77483,653
Alabama,Dale County,49129,927
Alabama,Dallas County,46365,974
Alabama,DeKalb County,64452,753

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.

View 14 Replies View Related

Visual C++ :: Multidimensional Array Having 3 Rows And 8 Columns - Bubble And Selection Sort

Feb 19, 2014

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 },

[Code] ....

View 1 Replies View Related

C++ :: How To Use Bubble Sort

Feb 20, 2012

how can i use my function now in the main ... after i put the numbers for example i want them to be sorted in ascending or descending order

PHP Code:

# include <iostream>
using namespace std;
int main () {
    int array [10]; 
    cout << " enter numbers : ";
    for ( int i=0; i<10; i++)

[code]....

View 4 Replies View Related

C++ :: How To Optimize Bubble Sort

Mar 24, 2013

How to optimize this bubble sort program?

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;
int main() {
long *A;
A = new long[100000000];

[Code]] .....

View 2 Replies View Related

C :: Bubble Sort With Random Numbers

Nov 6, 2014

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;
}

[code]....

View 3 Replies View Related

C++ :: Trace Bubble Sort Using Integers

Mar 6, 2014

Trace the bubble sort using the following integers,which represent the elements in an array.

5,7,3,8,6,7,3

View 1 Replies View Related

C++ :: Sorting Golfers Using Bubble Sort

Oct 29, 2013

I have to sort golfers using bubble sort. Here my code:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
void tellUser();
double calcAvg( int, int, int, int, int &);
void swap( int &num1, int &num2);

[Code] ....

View 2 Replies View Related

C++ :: Bubble Sort - Put In Descending Order

Jan 22, 2014

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.

View 1 Replies View Related

C++ :: Bubble Sort Is Adding Its Own Number

Dec 10, 2013

When I run the program the first int that is stored in the array keeps changing to -858993460.

#include <iostream>
using namespace std;
int main() {
int i;
int j;

int testScore[5];
int count;

[Code] .....

View 1 Replies View Related

C++ :: How To Bubble Sort Data From A File

Sep 26, 2014

I'm trying to write a program that will print the data of 10 records from a file and then, sort them descending to ascending by year.

Here are the records:

NameYearTuition
David20111582.38
Sylvester2012728.82
Ben19920
Brandon1995500.25
Riley1997845.19
Mark2009700.05
Roberts2002450.87
Butler2005920.78
Steve20001000.00
Joe19941200.15

Here is my code so far:

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;

[Code] ....

How do I go about arranging it?

View 1 Replies View Related

C++ :: Program To Implement Bubble Sort

Feb 15, 2015

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

View 1 Replies View Related

C++ :: Sorting And Searching With Bubble Sort?

May 15, 2014

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]

View 1 Replies View Related

C/C++ :: How To Bubble Sort Data From A File

Sep 26, 2014

I'm trying to write a program that will print the data of 10 records from a file and then, sort them descending to ascending by year.

Here are the records:

NameYearTuition
David20111582.38
Sylvester2012728.82

[Code].....

View 6 Replies View Related

C/C++ :: Bubble Sort Two Arrays Program

Apr 15, 2015

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.
*/

#include <stdio.h>
#include <string.h>
#include <stdio.h>
#define SIZE 5

void input(char fullname[][25], int age[]);
void output(char fullname[][25], int age[]);

[Code] ....

View 14 Replies View Related

C++ :: Writing A Bubble Sort With No Loops?

Mar 23, 2012

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.

Code:
#include <stdio.h>
#include <iostream>
#include<fstream>
#include<string>

[Code].....

View 14 Replies View Related

C :: Implementing Selection Sort Algorithm

Jun 14, 2014

So i'm trying to implement the selection sort algorithm and it seems that the code is fine but...

Code:
#include <cs50.h>
#include "helpers.h"
void
sort(int values[], int n) {
// TODO: implement an O(n^2) sort

[Code] ....

I keep getting these errors and i don't understand why:

/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

View 3 Replies View Related

C++ :: Selection Sort 2D Char Array

Feb 18, 2014

How to sort the last name instead of first name. Everything works so far and sorting is done on the first character.

#include <iostream>
#include <cstring>
using namespace std;
void sort(int, char[10][40]);
int main() {
char twoD[10][40];
int input = 0;

[Code] .....

View 4 Replies View Related

C :: Bubble Sort - Output In Descending Order

Feb 1, 2014

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

[Code] .....

View 4 Replies View Related

C++ :: Applying Bubble Sort On Linked List

Feb 27, 2015

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.

View 1 Replies View Related

C/C++ :: Bubble Sort Not Working For Array Of Strings?

Apr 9, 2015

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>

[Code].....

View 1 Replies View Related

Visual C++ :: Bubble Sort Is Making Up Its Own Number

Dec 10, 2013

i cant figure out what im doing wrong with my bubble sort. when i cout the sorted test scores, the first number(testScore[0])this is the code.

#include <iostream>
using namespace std;
int main()
{

[Code]....

View 2 Replies View Related

C :: Selection Sort Program Crashes Right After Value Entered

Mar 25, 2014

I'm trying to code a Singly-Linked List(Double Pointers) selection sort program and I can't tell what the problem is. My compiler says no errors but when I run the program, it crashes right after I enter the values.

Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

typedef struct node{
int elem;
struct node* link;

[Code] ....

The compiler that I'm using is Dev-C++.

View 2 Replies View Related

C :: Sorting Strings Using Selection Sort Method?

Dec 7, 2013

I am trying to write a program to sort the characters in a word alphabetically. For example, if you input 'what', the computer will sort it into 'ahtw'. But, it fails to work. I didn't know why.

Code:

#include <stdio.h>
#include <string.h>
main() {

[Code].....

View 8 Replies View Related

C++ :: Calculate Total No Of Comparison Using Selection Sort?

Sep 15, 2014

how to put comparision condition in order to caculate total number of comparision in selection sort

static void selectsort(int[] data, int n)
{
int i, j;
for (i = 0; i < n; i++)

[Code]....

View 1 Replies View Related

C++ :: Selection Sort On Array Of Class Objects?

Jan 24, 2013

I have written a selection sort algorithm to go sort an array of class objects by age in ascending order, the problem is that the output being given does not match what i think the code should do. when the program runs the 3 records are added to the array and when they are sorted should be outputed in ascending order, the problem is that with my code the last 2 are sorted properly but the first element does not seem to move, it remains the same as the original unsorted value.

My code for the selection sort function and the display method are below:

void selectionSort() {
int i, minIndex, minValue;
for (i = 0; i < (arrlength - 1); i++) {
minIndex = i ;

[Code].....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved