C++ :: Sorting Array With Double Bubble?

Feb 3, 2013

i wanted to sort an array with double bubble sort but it didnt work!

my code is this:

void doubleBubbleSort(int *array, int length) {
int i,j;
for(i=0; i<length--;i++) {
if(array[i]>array[i++])
for(j=i;j>=0&&(array[j]>array[j++]);j--)
std::swap(i,j);

[code].....

how to get time like 1.56 seconds,too!

View 3 Replies


ADVERTISEMENT

C++ :: Bubble Sorting A Classed Array

May 8, 2014

I'm really struggling with bubble sorting a classed array(an inventory). I understand bubble sorting in theory and implementing it into a static array makes sense. When I get to doing it in a classed array then I struggle. I need to sort the weight by bubble sort (then selection sort for name, and insertion sort the cost; but I want to tackle one problem at a time.

Here is the code:

#include <iostream>
#include <iomanip>
#include <conio.h>
#include "Inventory.h"
#define MAX_REC 10
using namespace std;
//Class to hold inventory variables/funcitons

[Code] ......

View 6 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++ :: Sorting Randomized Array Of Integers Using Bubble Sort Algorithm?

Jun 26, 2013

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;

[Code] .....

View 1 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++ :: Store User Input In Array And Calculate Mean / Median And Mode - Bubble Sorting

Mar 26, 2014

I'm trying to make a c++ program of this but i don't know how to use the bubble sorting.

Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.

Mean is the average of the 10 numbers.
Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.)
Mode is the most frequent number among the 10 numbers.

View 5 Replies View Related

C++ :: Bubble Sorting Of Strings

Sep 20, 2013

I have to read data from a text file, load it into an array and then bubble sort it! Here is my code:

Code:
#include <iostream>
#include <string>
#include <fstream>

[Code]....

Basically what i am trying to do is that sort the names of 10,000 movies and then write those names to a text file. It gives an error in the nested loop by underlining arr and tells that no suitable conversion function from std::string to const char* exists.

View 5 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 Sorting With Function Templates

Jun 21, 2013

i'm new to C++ i came across this bubblesort program earlier relating to class templates i was wondering how to make this into simple function templates

#include<iostream>
#include<iomanip.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
template <class t>
class bubble

[Code] ....

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

C :: Bubble Sorting Failed - Prints A Blank Record

Feb 19, 2014

Well still working on my project, now the bubble sorting failed. For some reason the first slot in the array is empty and when I attempt to enter a record to access, it just crashes or prints a blank record. Here is my code for the viewing of the record and a SS of the empty array slot.

Code:
void searchRec(void) {
void Printing(int *ver, int *max);
FILE *fPtr;
struct Students vStudnt;
int set;
int ver;
int i = 0;
int fin = 0;
int sel;
char order;

[Code]...

Well I don't see why there is a empty slot, why?

View 6 Replies View Related

C++ :: Bubble Sorting With User Defined Amount Of Elements

Feb 25, 2014

I am writing some code to bubble sort a list of randoms numbers, 10 at the moment. I want to be able to user input the amount of elements that would be sorted. I think i'd have to use vector instead of arrays, but unsure how to do this. Or, how to be able to change the size of the array.

#include <iostream>
using namespace std;
#define SIZE 10

float numbers[SIZE];
int move_n;

[Code] ....

View 1 Replies View Related

C++ :: Bubble Sorting Linked List That Creates 100 Random Integers?

Feb 1, 2015

I am relatively new to C++ and am trying to bubble sort my linked list that creates 100 random integers. Everything works, but I am unsure how to continue this to include a bubble sorting method.

#include "stdafx.h"
#include <iostream>
using namespace std;
class Node{
public:
int data; //set data

[Code] ....

View 1 Replies View Related

C++ :: Import A File Containing Words And Numbers To Linked List - Bubble Sorting

Feb 16, 2013

I have a code able to import a file containing words and numbers to a linked list, but I also need to sort this linked list alphabetically. I've done research on this involving bubble sorting, but no explanationcan achieve this objective.

Below is the code that can only put the file into linked list:

Code:
#include<iostream>
#include<conio.h>
#include"U:C++WordClass2WordClass2WordClass.cpp"
#include<fstream>
#include<vector>
#include<string>
using namespace std;

[Code] .....

View 5 Replies View Related

C++ :: Bubble Sorting Vectors - Display Highest Temperature And Occurrence Time

Feb 12, 2013

I'm doing a project where I have to store information gathered (temperature and the time it was taken in seconds) in two separate vectors. After an unknown amount of data has been entered, and the end-of-file has been reached, I have to display the highest temperature and the time(s) it occured (bear in mind that the highest temperature may be recorded more than once). The output of that part should be as follows:

Highest temperature: 51
Recorded at time(s):
22:45
2:27

Something like that. The time should also be converted to hours and minutes. To the point: I've done some research on bubble sorting, but they only use it for arrays.

View 3 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++ :: 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++ :: Should Use Vector Or Just Double Array

Dec 15, 2014

I am programming about some numerical problems. I know that vector supplies vector operations. But vector always allocate more memory (used when the size changes). My matrix or array never change size, and the vector operation is just +,-,dot,cross,distance

My question is that should I use vector, or simple double array with new & delete is enough for me?

View 6 Replies View Related

C++ :: Getting A File Into A Double Array?

Dec 20, 2014

The assignment is to create a program that lets users reserve a spot on a plane either in coach or first class. I'm supposed to create a .txt file to use as the prices for different seats and while I have done that, I'm having trouble getting the file into a double array.

This is what I have so far.

//This program lets the user reserve airline tickets on a plane
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;

[Code]....

Once I have the file into a double array, I have to use that array to implement it into the seat prices. Such as if user chooses to sit in row 1 seat 1 it would be that price. Also the '#' means open seat and '*' means seat taken. O yea, under the "//Populating the double array" is me trying to see if a for statement or a nested for statement would work.

View 5 Replies View Related

C :: Convert Char Array To Double

Mar 6, 2015

How to convert char array into double?,i.e. store char array values into a single double variable. Below is the code that i'm working. Im extracting the value "2255.1682" from char array gpsdata1. I used while loop, extracted the value and stored in "myChar", but i want to store it in double variable "lat1".

Code:
#include <stdio.h>
#include <stdlib.h>
int main(){
unsigned char gpsdata1[]="$GPGGA,091310.000,2255.1682,N,11356.3605,E,1,4,1.62,164";
char myChar;
double lat1;

[Code] .....

View 5 Replies View Related

C++ :: Initializing Double Pointer Array?

Aug 1, 2013

How to initialize double pointer array..?

int (**aLines)[2];

View 3 Replies View Related

C++ :: Converting String Into Double Array

May 18, 2014

I am having a lot of trouble extracting values from a string into a double array.

I have a string that looks something like this: "asdf 1.320 1 234.43 5.00000 3"

All I want to do is extract the doubles and store them in an array of doubles.

View 8 Replies View Related

C++ :: Mesh Array Of Double Boost

Jul 11, 2012

I wanna create mesh Array using boost elements, that will be do the same that code below, but can accept numbers of double. Any boost array that give me needed functionality. It will be great that advised element has the same argument list. I mean

// [base,stride,bound)
// [0,2,4)

Or may be there are any opportunity modify this boost::multi_array_types::index_range in order do make it accept double...

1>------ Build started: Project: HP_A.1_d_, Configuration: Debug Win32 ------
1> Main.cpp
1>c:all myс++ha level 9solutionlevel 9hp_a.1_d_main.cpp(15): warning C4244: 'argument' : conversion from 'double' to '__w64 int', possible loss of data
1>c:all myс++ha level 9solutionlevel 9hp_a.1_d_main.cpp(15): warning C4244: 'argument' : conversion from 'double' to '__w64 int', possible loss of data
1>c:all myс++ha level 9solutionlevel 9hp_a.1_d_main.cpp(18): warning C4244: 'argument' : conversion from 'double' to 'unsigned int', possible loss of data
1>c:all myс++ha level 9solutionlevel 9hp_a.1_d_main.cpp(20): warning C4244: 'argument' : conversion from 'double' to 'unsigned int', possible loss of data
1>c:all myс++ha level 9solutionlevel 9hp_a.1_d_main.cpp(20): warning C4244: 'argument' : conversion from 'double' to 'unsigned int', possible loss of data
1> HP_A.1_d_.vcxproj -> C:all myс++HA level 9SolutionLevel 9DebugHP_A.1_d_.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Code:
#include <boostmulti_array.hpp>
#include <iostream>
typedef boost::multi_array_types::index_range range;

[Code]....

View 1 Replies View Related

C++ :: Byte Array To Double Conversion?

Dec 5, 2014

I'm trying to understand why a conversion from a byte array (unsigned char) to a double works when done one way and not antoher.

In the example code I test by hard coding an unsigned char array of the same bytes that the double consists of.

When I copy the bytes to a long long and cast to double the result is not the original double but if I use a struct the bytes can be set and the conversion happens.

Seems to me that both ways should work. I'd just like to know what is going on with the "struct way" that makes the conversion correct. I see in debugger that the bytes in memory are the same for piAsLong and u.bytes.

My compiler is VS 2012 and a long long and double are both 8 bytes (tested with sizeof). This is learning activity only.

Code:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
union {
double d;

[code]....

View 6 Replies View Related

C :: Putting Float Numbers Into Double Array

Jan 29, 2014

So I have a double array, where I'm inputting float numbers to certain points in an array. Sometimes, the numbers that are printed out are completely different from what I put in.Here is the part of the code:

Code: .

while( token != NULL ) {
num = atof(token);
test[j][i] = num;
printf( "
%s, i is %d, j is %d
", token,i,j );
printf( "number is %f
value test of i,j is %f

[code]....

Why the float num prints out fine, but when put into an array becomes garbage?I'm taking string values from a csv file and turning them into floats, but no problems seem to crop up there.I reset i when appropriate and increment j when needed, so I don't think my problems are from incorrect array values (though they might be)

View 2 Replies View Related







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