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


ADVERTISEMENT

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 :: Write Program To Sort 2 Ints On Ascending / Descending Order?

Jan 24, 2014

I'm trying to write a program to sort 2 ints on ascending/descending order, using function pointers. here is my code so far:

Code:
#include <stdio.h>
#include <stdlib.h>
int min_el(int a,int b);

[code]....

View 6 Replies View Related

C++ :: Enter Number Or Letter And Sort In Ascending Or Descending Order

Jan 8, 2013

Assignment:

1. Choose what to enter NUMBER or LETTER.
2. Choose type of sorting ASCENDING or DESCENDING.

#include<iostream.h>
#include<conio.h>
main() {
int x,y,z;
cout<<"choose Number or letter
1.number
2.Letter";

[Code] ....

View 9 Replies View Related

C++ :: Sort Players In Descending Order On The Basis Of Score - Program Not Working Properly

Feb 11, 2015

#include <iostream.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

class Player {
private:
char name[20];
int score;

[Code] .....

View 5 Replies View Related

C++ :: Sorting Array Of Numbers Into Ascending Order - Bubble Sort Keeps Crashing

Oct 29, 2014

I am trying to write a program which will sort an array of numbers into ascending order, here is my code

#include<iostream>
#include<cmath>
using namespace std;
int main(){
int array[]={1, 5, 17, 3, 75, 4, 4, 23, 5, 12, 34, 34, 805, 345, 435, 234, 6, 47, 4, 9, 0, 56, 32, 78};

[Code] .....

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.

View 2 Replies View Related

C/C++ :: Put Numbers In Ascending / Descending Order

Nov 9, 2014

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;

[Code] .....

View 7 Replies View Related

C++ :: How To Store Data By Descending Order Auto

Oct 27, 2014

I wanna store my data by descending order auto without doing a classification after , i have come up with a code but it crashes.

Code:
void list::create(int num) {
struct node * n,*temp;
n=new node;
n->data=num;
if(head==NULL)

[Code]....

I don't wanna use the list library with the push.buck, i need to do it by coding it without fix functions ....

View 3 Replies View Related

C++ :: Sorting Numbers In Both Ascending And Descending Order?

Sep 7, 2014

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?

View 3 Replies View Related

C :: Sorting Array Alphabetically - Print 10 Names In Ascending Or Descending Order

Apr 9, 2014

//Build a program that uses a single-dimension array to store 10 names input by a user.

//After inputting the names, the user should see a menu with two options to sort and print the 10 names in ascending or descending order.

insert
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char names[10];
char temp[10];
int count,i,j;
int sort;

[Code] .....

View 10 Replies View Related

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 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++ :: Bubble Sorting Array In Ascending Order

Nov 18, 2014

I'd like to modify this code so that there is 1000 numbers instead of 100, and that they're sorted in ascending order instead of descending order.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
double* sort_array(double* sort) {
for (int a=1; a<100; a++) {

[code]....

View 2 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 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++ :: 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







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