C++ :: Radix Sort Program Implementation On Main CPP File

May 11, 2014

I'm having trouble implementing my radix sort program on the main .cpp file. Here is what the radix header file looks like::

#include <vector>
#include <queue>
using namespace std;
void distribute(const vector<int> &v, queue<int> digitQueue[], int pwr) {
int i;
for(int i=0; i < v.size(); i++)
digitQueue[(v[i]/pwr) % 10].push(v[i]);

[Code] .....

Here is what my main looks like:

#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include "radix.h"

[Code] ....

My output:

sorted array is:
0 0 0 0 0 0 0 0 0 0

View 1 Replies


ADVERTISEMENT

C++ :: Radix Sort Not Working - Implementation Using Two Tables

Jun 13, 2014

I'm trying ultimately to do a radix sort. I'm going with the implementation using two tables. One will initially hold the unsorted values then hold the partially sorted values thereafter. The other will be an array of linked lists which will be where the radix sort is done. Here is my code thus far:

Main

#include <iostream>
#include <fstream>
#include "radix.h"
#include "radix.cpp"
using namespace std ;
int main ( int argc , char * argv [ ] ) {
ifstream input ( argv [ 1 ] ) ;

[Code] ....

It appears to be crashing during void insert_into_sorted ( int to_insert , int place ) ; and I'm not sure why.

View 2 Replies View Related

C :: Radix Sort Function To Sort Array Of 64 Bit Unsigned Integers

Aug 19, 2013

Example radix sort function to sort an array of 64 bit unsigned integers. To allow for variable bin sizes, the array is scanned one time to create a matrix of 8 histograms of 256 counts each, corresponding to the number of instances of each possible 8 bit value in the 8 bytes of each integer, and the histograms are then converted into indices by summing the histograms counts. Then a radix sort is performed using the matrix of indices, post incrementing each index as it is used.

Code:
typedef unsigned long long UI64;
typedef unsigned long long *PUI64;
PUI64 RadixSort(PUI64 pData, PUI64 pTemp, size_t count) {
size_t mIndex[8][256] = {0};
/* index matrix */
PUI64 pDst, pSrc, pTmp;
size_t i,j,m,n;
UI64 u;

[Code]....

View 9 Replies View Related

C++ :: Why To Use Radix Sort

Apr 10, 2013

why we use radix sort.

View 2 Replies View Related

C :: Space Complexity Of Radix Sort?

Sep 2, 2013

I was just going through Radix Sort algorithm. Though I got the logic and the concept used in it, I am still pretty much confused about the space complexity being O(k+n) for this algorithm. (where, k is the max no of digits in a number, and n is the no. of inputs to be sorted).

View 1 Replies View Related

C++ :: Column Based Database - Constructing Very Fast Radix Sort

Apr 12, 2014

I'm attempting to build a column based database, and I'm new to C++ (just wanted to play around with building a column base database "for the fun of it"). I want to construct a very fast radix sort, that would allow me to quickly sort groups of columns based on integer values. My general preference is to take up more RAM to get more performance.

I'd like to build the radix sort by allowing 256 "buckets" to drop values in as I'm sorting. This allows me to sort through a group of 4 byte integers in only 4 passes. But assuming I'm trying to sort a large group of values (say 50+ million), I'm not sure what type of container to use for these. Also note I'm pretty unfamiliar with the "standard library", so below are my thoughts:

Vectors:
-Pros: Easy to use, and very fast for sequential and random access inserts / reads
-Cons: If they have to dynamically resize because a given vector wasn't large enough, this can apparently really slow performance. Unless I make another pass over the numbers before I start sorting, I wouldn't know how big to make individual the individual vectors. This means I either have to make them "too big" and waste space, or pay a performance price for either resizing, or scanning data first.

Lists:
-Pros: Seems like I wouldn't have to specify size ahead of time, so I could just easily insert values to a given list. Also, since I don't need random access reads (I'll ready the "0" list sequentially, then the "1" list, etc. they should work fine.
-Cons: I don't really know much about lists, but I'm not sure how easy it is to append a new value to the end of a list. I've read that standard library lists include both "forward" and "backward" pointers, which I don't need. Also, I find it hard to believe that there isn't some time taken up with memory allocation. If I build a list and append x million records in it, is it calling memory allocation routines x million times?

Or maybe there's another container type I should learn?

Again, my goal is to make this "fast", not "memory efficient". But having said that, the fastest way I could think of (use 256 vectors, each sized equal to the total number of members to be sorted) is just too much memory to burn - 256 times a vector big enough to hold millions of elements is too much.

View 4 Replies View Related

C++ :: Merge Sort Implementation Giving Incorrect Output

Oct 25, 2014

I've implemented the merge sort algorithm and used the 'merge' part for counting the number of split-inversions in an array as part of an assignment for an online course. How ever, the out put array is not a sorted version of the input array and as a result the number of split inversions obtained is wrong. I think that there is some thing wrong in the way I am indexing arrays.

I've used ' cout ' to print the values of indexes to see exactly what values are being passed in during the recursions.

Code:

#include <iostream>
using namespace std;
int length=0,mid=0,inv=0;
void mergesort(int arr[], int first, int last) {
cout << "first: " << first << " " << "last: " << last;
cout << endl;

[code].....

View 5 Replies View Related

C++ :: Implementation File Versus Header File - Eclipse Giving Errors

Feb 10, 2013

I have written my program and it works when I keep everything in the header files, and then have my main. I am now splitting them up into implementation files, but Eclipse keeps giving me errors. It gives me error at every opening brace of the constructor and functions. It says on all of them "Redefinition of (name of constructor or method), Previously declared here." What am I doing wrong, because it works in the header file?

#include "KeyValuePair.h"
template<typename Key,typename Value>
KeyValuePair<Key,Value>::KeyValuePair()

[Code] .....

View 3 Replies View Related

C :: Implementation Of Graphs In The Form Of Program

Feb 13, 2013

How a graph can be implemented in the form of a c program?

View 2 Replies View Related

C++ :: Splitting Template Class To Header H File And Implementation CPP File

Sep 12, 2014

What is the right syntax for implementing the .cpp of a template class?

Consider this LinkedList.h file:
Code: #include<iostream>
#include"Iterator.h"

template <class T>
class LinkedList {

[Code] ....

How should the implementation for the LinkedList constructor, for example, should look like in the LinkedList.cpp file?

I tried this:

Code: #include "LinkedList.h"
template <class T>
LinkedList<T>::LinkedList<T>() {
// constructor
}
LinkedList<T>::~LinkedList<T>() {
// destructor
}

But the compiler wouldn't accept it.

View 4 Replies View Related

C :: Program To Evaluate Postfix Expression Using Array Implementation Of Stack

Apr 26, 2014

Write a program that evaluates postfix expression using array implementation of stack.

The expression [the input] is evaluated from left to right using a stack. When the element read from the expression is an operand, push it into the stack.When the element read from the expression is an operator: Pop two operands from the stack.Evaluate the two operandsPush the result of the evaluation into the stack.

The final result lies on the top of the stack at the end of the calculation. Make sure to display the result before terminating the program.Write a program that evaluates postfix expression using array implementation of stack.

Code:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define M 20

typedef struct{

[Code] ....

View 1 Replies View Related

C++ :: Best Way To Split Main Program?

Apr 26, 2013

I need to split my main() function into two separate functions.Where would the best place be to split it up?

* Read a text file whose name is given on the command line, and for each word:
* if it is an integer, insert it into an array in sorted order
* if it is not an integer, insert it into an array of words.

* Notes: converted to use C++ strings, because C strings are messier.
* Need to grow arrays, need to insert in sorted order.
* Growing arrays might be done the way we grew a C string:

* bigger = new <type> [size+1]
* for(i=0; i<size; i++) {
* bigger[i] = oldarray[i];

[code]....

View 1 Replies View Related

Visual C++ :: Class Specification / Implementation File

Oct 2, 2013

I keep getting this error

In file included from /usr/lib/gcc/i686-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/ios_base.h:43:0,
from /usr/lib/gcc/i686-redhat-linux/4.5.1/../../../../include/c++/4.5.1/ios:43,
from /usr/lib/gcc/i686-redhat-linux/4.5.1/../../../../include/c++/4.5.1/ostream:40,
from /usr/lib/gcc/i686-redhat-linux/4.5.1/../../../../include/c++/4.5.1/iostream:40,
from player1.cpp:3:
/usr/lib/gcc/i686-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/locale_classes.h:45:1: error: expected unqualified-id before "namespace"

What does it mean? I am working on classes and this error comes when I run the implentation of my class file.

//Implimentation of class player1 (player.cpp)
#include "player1.h"
#include <iostream>
//using namespace std;
void player1 :: Set_Name()

[Code] ...

View 2 Replies View Related

C :: Function Calling In Main Program

Aug 17, 2013

I have i want to call a function with two results for example x = 1 and y = 2.How do i return this function in c and how do i call such a function in the main program.

View 9 Replies View Related

C++ :: Linked List Interface / Implementation And Driver File

Jun 12, 2013

I am having difficulty calling the constructor in interface portion of my program. I get the error: no matching function for call to ‘Node::Node(int, NULL)’ when I try to call it on line 26 within the main function.

code:
interface: [URL]
implementation: [URL]
main file: [URL]

View 7 Replies View Related

C++ :: Separating Routines Into A Separate Implementation And Header File

Oct 18, 2013

I am trying to separate out particular sets of routines into a separate implentation and header file which can be compiled independently to the main program such that the program source consists of a file called customers.h, customers.cpp, and exercise_1_5.cpp

Each of the files should contain the following:

customers.h should contain the definition of the customer structure and the declaration of print_customers.

customers.cpp should contain the implementation (or definition) for print_customers.

exercise_1_5.cpp should contain an include of customers.h and the main program.

This is my original code from a single .cpp file

#include<iostream>
#include<string>
using namespace std;

[Code].....

The error messages I am getting from the compiler on the customers.cpp file:

C:UsersBenDocumentsCS264lab3customers.cpp:5:22: error: variable or field 'print_customers' declared void
C:UsersBenDocumentsCS264lab3customers.cpp:5:22: error: 'customer' was not declared in this scope
C:UsersBenDocumentsCS264lab3customers.cpp:5:32: error: 'head' was not declared in this scope

View 6 Replies View Related

C :: Write A Program With Two Functions Both Called From Main

Mar 14, 2013

Write a program with two functions both called from main(). The first function just prints "Hello". In the second function ask the user to enter a number. Calculate the square root of the number and return the result to main(). In main() print the square root value.

Code:

#include<stdio.h>
#include<math.h>
float fun3 (float );
main()
}

[code]...

View 3 Replies View Related

C++ :: Program To Display Other Functions In Int Main Function

Oct 13, 2013

I would like my program to display other functions in the int main function. For example, this is what my program looks like:

int Function1(int &var1, int &var2, int &var3) {
cout << "blah blah blah" ;
cin >> var1 ;
var2 = var1 * 3 ; //example
var3 = var1 * var2 ; //example
if(blah blah blah)

[Code]...

View 2 Replies View Related

C/C++ :: Program Crashing On A Function Call In Main?

May 5, 2014

i have this program I am working on and it seems to crash after the function call getdata()

here is the code

#include<iostream>
#include<string>
#include<cstdlib>

[Code].....

View 1 Replies View Related

C++ :: Construct A Program Without Main Function That Output Stars

Nov 5, 2013

I am trying to construct a program without a main function that outputs stars but at the same time outputs the number and a colon after the number but before the number of star. This is the coding i have so far.

void output_stars(int num){
if (num > 0){
cout << "*";
output_stars(num-1)

[Code] ....

The program is working the way it should i just can't figure out how to output the number and a colon. The main function is written as such:

output_stars(1);
output_stars(2);
output_stars(5);
output_stars(3);
output_stars(4);
output_stars(7);

How to get the numbers of the main function to show up with the stars of the previous function.

View 6 Replies View Related

C# :: Picture Cropping Code Causing Error In Main Program

Jan 24, 2014

Ok, this thing works as far as the getting the image and drawing the rectangle but for the life of me I cannot figure out why it is causing an in the program.cs.

public partial class Crop : Form {
public Crop(Image BaseImage) {
InitializeComponent();
if ((Bitmap)BaseImage != null) { pbOriginal.Image = BaseImage; }

[Code] ....

BaseImage is pulled in from the main form's picture box.

View 14 Replies View Related

C++ :: Using A Class File In Main File?

Feb 7, 2015

I'm having trouble working the two files together. I keep getting this error

error LNK2005: public:_thiscall datype::daytype(void)"(??0daytype@@QAE@XZ) already defined in createdaytype.obj

The same error are coming up for my printday function

Here is the daytype.cpp class code

#include <string>
#include <iostream>
class daytype {

[Code]....

View 2 Replies View Related

C++ :: Program To Sort Lists?

Aug 12, 2014

What I want to create is a program that sorts through a huge list (millions of lines).

I want it to get rid of any line that contains a word that isn't in an English dictionary.

Example list:

00sdfdsf
ahdadsg
angel
ksjflsjdf
green
green000
carrot

and it would go through millions like that, giving me only:

angel
green
carrot

as my new list.

How could I go about this? What programs would I need? And at the very least how can I remove unwanted things like numbers, double letters, underscores etc.?

View 3 Replies View Related

C :: File Opened In Main And Passing Pointer To A Function

Sep 14, 2013

I am getting a few compile errors for what might be a simple thing to do. I am opening a file in main, passing that pointer to a function and checking the contents of that file with a regex before I pass it on to build a BST. I am getting the following compile errors, what is wrong. Here are the errors:

Code:
gcc main.c fileCheck.c -o tree
main.c: In function `fileCheck':
main.c:19: error: syntax error before "FILE"
fileCheck.c: In function `fileCheck':

[Code] .....

Fatal error: Command failed for target `tree' Here is the two files and header that seem to be causing me the problems.

main.c

Code:
#include "main.h"
//#include "node.h"
int main(int argc, char *argv[])
FILE *fp;
if (argc > 2)

[Code] ....

And the header file.
main.h

Code:
#ifndef MAIN_H
#define MAIN_H
#ifdef __cplusplus
extern "C" {
#endif

[Code] .....

View 2 Replies View Related

C/C++ :: Passing Var Assigned In A Class File To Functions Outside Of Int Main?

Dec 7, 2014

I'm trying to pass the value of an object created from a class file to a function outside of the "Int Main" function in the main.cpp file. I've successfully created the object, I just want to pass it to a void function but I'm getting the scope error below. I'm not sure how to correct. I'm not having much luck with research either (static variables?).

error: 'TicTacToe' was not declared in this scope

main.cpp
#include <iostream>
#include <cstdlib>
#include "Signature.h"
#include "Gameplay.h"
using namespace std;
// Initialize array
char square[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

[code]....

View 4 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







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