Visual C++ :: Arbitrary Sort Algorithm For Input (Bunch Of Rows)
Apr 5, 2013
C++ sort algorithm or library that can take input of a bunch of rows of data and then sort rows by an arbitrary defined order of one of the columns ... i.e., sort rows by value of the first column in this order (boba bobc bobe bobx) etc?
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 am trying to sort a Report Table by which the user can enter any column or row number and output the results. And also sort by names as well. And from my code
#include "stdafx.h" #include<iostream> #include <string> #include<iomanip> using namespace std; #include <stdlib.h> /* srand, rand */ #include <time.h> /* time */
[Code] .....
I know I need to start somewhere with a void function and put in a selection sort.
I'm trying to make a program that allows the user to input an arbitrary amount of numbers and finding the largest of all the inputs but I keep having problems with the output.
javascript:tx(' #include <iostream> using namespace std; //****************************************** //CLASS COMPARATOR //******************************************
class comparator { public: comparator();
[Code] .....
And regardless of what numbers I enter, I always get the output of 10. Also I got the EOF idea from my textbook so if there is a better way of doing this I'd like to hear it. I don't know any clear ways that looks nice to end the while loop when the user doesn't have any more numbers to enter.
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
I'm trying to implement the Merge-Sort algorithm. I only had the pseudocode for it and have some problems coding this into C.
I have only covered pointers recently and I tried using them, which did not work. I started with the code for the merge algorithm and only used a 10 element array, which was already divided into two sorted subarrays:
Code: #include <stdio.h>#include <stdlib.h> int main() { int a[5]={1,5,6,10,13}, b[5]={4,8,9,10,14},c[10], *i,*j,k;
[Code].....
This is the result that I get:
Code: 1 4 5 6 8 9 10 10 13 0
So I think the problem occurs because in the second to last loop i is incremented again, but the end of the array is already reached, and the compiler has no element a[6] to compare with *j in the last run of the loop. Is there generally a better way to implement Merge?
I'm tinkering with a serial quick sort algorithm. Normally I use qsort() but I wanted to test this.
Somehow I loose the highest number. I can't see where I drop it.
Code: // function to quicksort, leave them in front of qsort. void swap(float_t *left, float_t *right){ float_t temp; temp = *left; *left = *right; *right = temp;
So I have an insertion sort function implemented that sorts through an array, but I'm having a problem showing the correct number of comparisons to work.
Each time I'm checking a value with another, the counter should update.
For instance, having an array of 10 elements going from 10-1 should give 45 comparisons, but I'm getting 54 comparisons.
void insertionSort(int a[], int& comparisons, const int& numOfElements) { int j, value; for (int i = 1; i < numOfElements; i++) { value = a[i]; for (j = i - 1; j >= 0 && a[j] > value; j--)
I've written code for a selection sort algorithm to sort through a singly linked list, However, it only brings the smallest node to the front, but doesnt swap positions of any of the remaining nodes, even though they are not in order.
I developed the following heap sort algorithm code, and for some reason anytime it goes above 4100 entries, the algorithm completely crashes. It works perfectly up until that point but I can't see why it would crash?
void heap_from_root(MVector &v, int i, int n) { int end=n,j=0; // Identify the lowest root and how many sons it has. If it only has one son, set j=1. if (n==1) { n = 0; j = 1; } else if ((n-2) % 2 == 0) { n = (n-2)/2; } else if ((n-1) % 2 == 0) { n = (n-1)/2; j=1; }
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;
How to draw a hollow triangle given a user input indicating the number of rows.
Eg: Number of rows = 4 ___* __*_* _*___* *******
My idea was to split up the triangle into three parts (first row, middle part, last row) and I've managed to write some code on printing the first and last row of the triangle
Code: int main() { //Declaring the variables. int rows, position; //Prompts user to enter number of rows. printf("Enter the number of rows in the triangle: "); scanf("%d", &rows);
[Code] .....
What to do so that I can print the middle part of the triangle. All I know is that I need to use loops. I've also been told that drawing a flow chart would work but I really don't know how to even begin with a flow chart then transform it into code.
void Arrival_MainThread::Body () { t1 = new boost::thread((Arrive_Fctor()), 2); t2 = new boost::thread((Arrive_Fctor()), 10000); t3 = new boost::thread((Arrive_Fctor()), 3000);
Code: class Arrive_Fctor { public: void operator()(int mean) { m_Arrivals = new Arrivals(mean); m_Arrivals->Activate(); #ifndef NO_RESOURCE
[code].....
The order of arrivals always appear as 3,2,1 it can't be 1,2,3 or 3,1,2 or something like that?
The body method is called when m_Arrival->Activate() is executed, and it is running as an independent thread.
I was supposed to sort out an input, getting rid of chars and only using the numbers. So 5a6g7we87hj9 would become 567879. I might be wrong in some way, but I used
So the latest challenge from jumping into c++ is as following.
Code: Write a function that builds the multiplication table of arbitrary dimensions This chapter also talks a ton about 2d arrays.
So I've built my program thus far as this.
Code: #include <iostream> using namespace std; int drawTable(int,int); int main()
[Code] .....
So basically, the idea is that I can use the arrays dimensions as a placeholder, and just multiple them to get that specific spot, so table[0][0] = 0, [0][1] = 0 and so on. However the output actually seems to be randomly generated numbers so I'd like to ask, what am I doing wrong? Am I on the right track? Or have I missed the bus stop completely.
Question: What is the efficiency and big O of the selection sort algorithm when the input happens to already be in nondecreasing order?
Answer: Not sure... since the input is in nondecreasing order, such that example 0, 1, 1, 2, 3, 4, 4, 5 then there will be no swap, Just comparisons of emelemts. So it is big O of n
Code: #include <algorithm> #include <winsock.h> void some_func() { int result = std::min (0, 16384); }
Okay, but the above code consistently gives me error C2589: '(' : illegal token on right side of '::'. I'm building with VC8. If I don't #include <winsock.h> the code compiles correctly but it doesn't matter if I #include <winsock.h> before or after including <algorithm>
I guess it might be due to one of my #defines but I've tried the code in a very minimal program and I still get the error.
I have a problem to implement a recursive version of an algorithm that I made, I get different values. Here is the code so Iterative (OK) and Recursive code form that is not OK.
The data sets do not give equal:
The algorithm is given two source and target positions on a board, find the number of paths between them...
Input Example: 5 2 3 4 4
Output Example: 5
Iterative Algorithm ( OK )
Code: #include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <string.h> #include <vector> #include <queue> using namespace std; int n , dp [1000][1000], x, y, xx, yy;
I'm looking for a resource (possibly CPP) for which I could do the following on a windows and linux machine:
1) type a string message into a GUI control (or some other input that can be accessed by the resource).
2) run a resource script that puts the message through a hash function (or a custom hash function) and outputs the hash string.
3) have a reverse function available in order to decrypt the message in an input fashion just like step #1.
what open-source resource might be the best for this? Right now I am imagining typing a message into a text file, saving the file to a hard drive location, running a script on it replacing the old file with a new file that just has a hash string in it, then using that hash string for the encoded message.