C++ :: Standalone Sort Function For The Class

Apr 30, 2013

I need to write a standalone sort function, which will take a linked list parameter and sorts it. The function is included in the main list class as friend class: Code: friend void sort (UList<T>&) I need to submit separate SortIS.h file for insertion sort. Here is my code:

Code:

#include <iostream>
template <class T>
void SortIS(UList<T>& list)
{
T temp;
for (int i=1; i<list.size(); i++)
{
temp = list[i];

[Code]...

But the teacher said it didn't compile returning an error: "undefined reference to `void". What I am missing here?

View 6 Replies


ADVERTISEMENT

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++ :: How To Get Standalone Copy Of Regex Part Of Boost Library To Work In Project

Feb 18, 2012

So, I have spent the last week looking googling and researching how to get a standalone copy of the regex part of the boost library to work in a project. This project will be compiled on other machines and I CANNOT have the user install it.

Is there any way to do this?

So far, I have built the regex part: I have both .so files and .a files built. The thing that I'm unsure of is that these were built with gcc and I am using/will be using g++.

I have also finally got the bcp tool to work, and extracted the regex part and all of its dependencies.

I can't get it to compile any way I try to work it. I need this to be in a folder "regex/" folder in my directory.

I have used too many commands to paste them all, but the last I tried was this:

g++ -g -pedantic -Wall -o doit test.C -Iregex/boost/ -Wl,-Lregex/libs/regex/build/gcc/ -static -lboost_regex-gcc-1_47

I have also tried many variations of the above command. Such as using -lboost_regex and lots of other things. Is my whole problem because I'm using an .so built by GCC?

The output of the above command was

/usr/lib/gcc/i686-linux-gnu/4.6.1/libstdc++.a(eh_alloc.o): In function `__cxa_allocate_exception':
(.text.__cxa_allocate_exception+0xb4): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/i686-linux-gnu/4.6.1/libstdc++.a(eh_alloc.o): In function `__cxa_allocate_exception':
(.text.__cxa_allocate_exception+0x111): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/i686-linux-gnu/4.6.1/libstdc++.a(eh_alloc.o): In function `__cxa_free_exception':

[Code]...

View 4 Replies View Related

C++ :: How To Sort A 1D Array Using Function Sort

Mar 22, 2013

how to sort a 1D array using function sort().but if i have a 2D array how do i sort only 1 row of it (or column)?

View 2 Replies View Related

C++ :: Syntax Error In Function Call - Type Mismatch In Parameter In Function Sort

Jul 6, 2014

error says "cannot convert 'int*' to 'int' in function main()
and also
type mismatch in parameter in function sort(int,int)

Heres the code:
#include<iostream.h>
#include<conio.h>
void main() {
void sort(int,int);
clrscr();

[Code] .....

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

C++ :: Member Function In Derived Class Call Same Function From Its Base Class?

Sep 18, 2013

How can a member function in my derived class call the same function from its base class?

View 1 Replies View Related

C :: How To Make A Sort Function

Feb 28, 2013

Im suppose to make a "poor mans" variation to the Sort function built into unix. The program is suppose to read in a file and sort the contents of the file. So its a variation of the Unix Sort feature. I have remade the readLine function we were provided so that it doesnt use fgets. where to go from here, Not sure on how to make a sort function. Here are the reqirements of the program:

Code:

• Re-implement the readLine() function so that it no longer makes use of fgets(). Instead,
process the input on a given line character-by-character.

• Provide code which will create a data structure similar to argv to hold all of the words to be sorted. Use malloc() to ensure that each entry has just the required number of bytes needed to store the words. The final entry in your array should be the NULL pointer.

• Implement a sort() function which will rearrange the words in sorted order. To swap two words in your array, note that only a pair of pointers need to move. The strings themselves, once established, will never move. Heres what i have:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINES 1000 /* maximum number of reminders */
#define WORD_LENGTH 10 /* max length of reminder message */

[code]....

View 9 Replies View Related

C :: Multiplication With Sort Function

Oct 30, 2014

I need to include validation to only accept numbers and to only the last four odd numbers in the table.

Code:

#include <stdio.h>void main() {
int upper, range, i;
printf("Enter an integer to find multiplication table: ");
scanf("%d",&upper);

[Code].....

View 3 Replies View Related

C :: Sort Array By Function To Get Max Number

Mar 6, 2015

I have this code(homework) i've been working on for several days i couldn't fix this error.

Question is: to write a sort program in c . Ineed to ask user for how many numbers to be sorted(n) ask again for values. The approach of sort is this:

1- store n in temporary var (temp)
2- search for largest number in array (0 until temp-1)
3- switch the fied that store largest with field indexed by (temp-1)
4- temp-- (decrement)
5- repeat steps 2 to 4 until temp is 1

the program then prints the numbers of array on screen in one line. I also should use a function getMax(int *list , int n) that determines largest value and returns its location in that array

list : is the array
n: number of elements

Code:
#include<stdio.h>
int getMax(int *list, int n); //definition of getMax function
int main(void) {
int n,i;

[Code] .....

so i tried to sort this array

Code:
input 2 7 9 4 3 1 6 5
The out put should be : 9 7 6 5 4 3 2 1
instead it prints : 7 9 2 4 3 1 6

View 11 Replies View Related

C/C++ :: Sort String In Map Comparator Function

Jan 19, 2014

i am currently using a comparator function in STL map for sorting date of string data type in ascending value. My dates are in this format for e.g. 15OCT1990, 13SEP1980 and etc. I am using substring to split up the string so that i can compare day, month, year separately. Right now i have problem comparing the month portion because alphabetically "FEB" comes before "JAN".How can I make a fixed substring position of (2,3) which is my month value to accept that string value of JAN comes before FEB,AUG,DEC for e.g?

struct sortMapDaily: public std::binary_function <bool, std::string, std::string>
{
bool operator() (const std::string& lhs, const std::string& rhs)
{

[Code].....

View 5 Replies View Related

C :: Passing Array Into Function - Generic Sort

Mar 9, 2013

I'm passing an array into this function and it's taking the item at index 0 and replacing the rest of the array with it.

Code:
void generic_sort (void *arg, size_t num, size_t size, int (*cmpfnc) (const void *, const void *)) {
for (int i = 1; i < (int)num; ++i) {
int j = i;
char *tmp_address = malloc (sizeof (arg));
tmp_address = (char *)arg + j * size;

[Code] ....

View 13 Replies View Related

C :: Insertion Sort Function Crashing If 8 Or More Values?

Jan 15, 2015

This program I'm working on accepts an array size from the user, prompts the user to store that many integers, sorts them from smallest to largest, and then searches for duplicates with a simple for loop. The ultimate goal of the assignment was to display duplicates in an array, and the rest of the functions are just how I decided to reach that goal.

Anyway, my program crashes if I choose an array size larger than 7. It sorts and displays duplicates perfectly with 7 or fewer arguments.

The exact moment it crashes is after I enter the final value it prompts me for, so it appears my inputsize() function and my inputarray() function are working, and the error may be in the arrsort() function. Code is below:

Code:
#include <stdio.h>
int funcinputsize(int);
void funcinputarray(int [], int size);
void funcarrsort(int [], int size);
void funcdupe(int [], int size);

[Code] ...

View 4 Replies View Related

C :: Sort Lines Of Matrix In A Single Function

Jan 14, 2014

I need to write a code (in C99). The programe receives an input number (integer) 'n' and then a matrix sized n*n (matrix[n][n]), all numbers are integers. We're supposed to define the matrix's size with malloc. Now the program needs to sort the lines of the matrix (the number in each line), in a single function (!) this way:

even line index (0,2,4,6...): from small to big.
odds line index (1,3,5...): from big to small.
and then print it.
*note: first line is indexed 0, second line is 1, etc.

I was thinking to sort it with bubblesort function with the following if:
if(i%2==1)
do odds sorting.
else
do even sorting.
when i is the index of the row.

my problem is defining the malloc and how do I send the matrix to sorting.If needed I will attach my current (not so good (completly awful)) code and functions as well as an example of what the prog. supposed to do.

View 13 Replies View Related

C++ :: Store Random Numbers And Sort Function

Oct 7, 2014

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;

const int s = 12, p = 6;
int x[s][p];

[Code] ....

Names: P1 P2 P3 P4 P5 P6 AVER.

EVIKE 41 85 72 38 80 69 64.17
KKASV 65 68 96 22 49 67 71.86
YCXFX 51 61 63 87 66 24 70.64
FADPO 80 83 71 60 64 52 80.11
OEJUV 90 60 49 31 23 99 72.02
POEYL 94 11 25 24 51 15 48.67
VRVIP 13 39 67 97 19 76 59.94
QNQRQ 12 33 99 18 92 35 58.16
OOVAO 74 0 95 71 39 33 61.69
NCBXC 39 32 37 45 57 71 57.12
ATXDK 95 5 71 24 86 8 57.69
IXJSW 51 54 74 24 75 70 67.61
AVER. 58.75 49.15 72.35 51.11 62.68 56.81

1: Sort Alphabetically
2: Sort Grades Increasing Order (Student)
3: Sort Grades Increasing Order (Project)
4: End Program Enter choice: 2

Names: P1 P2 P3 P4 P5 P6 AVER.

XXZRZ 41 72 38 80 69 65 60.83
OKETL 68 85 22 49 67 51 67.14
GZQRC 61 63 87 66 24 80 74.69
OJWAY 83 71 60 64 52 90 82.45
PSAJL 60 49 31 23 96 94 72.57
AOVLZ 11 25 24 51 15 13 35.26
CPWSR 39 67 97 19 76 12 57.54
IZCOB 33 99 18 92 35 74 68.09
IJTVD 0 95 71 39 33 39 57.52
LDVGY 32 37 45 57 71 95 65.75
MBORX 5 71 24 86 8 51 51.79
XOHGM 54 74 24 75 70 0 58.13
AVER. 40.58 70.72 50.98 62.66 56.56 60.05

1: Sort Alphabetically
2: Sort Grades Increasing Order (Student)
3: Sort Grades Increasing Order (Project)
4: End Program Enter choice:

Why my sort is not working. Also, I want to keep the same random numbers for the continuation of the program, I don't want new randomized values when I display the table.

View 4 Replies View Related

C++ :: Generalized Sort Function Using Lambda Functions

Jan 15, 2014

How to improve my customSort function. It is to accept a lambda function as parameter which customizes your sort in any special way you want.

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <functional>

enum personType {teacher, student, baby};

[Code] ....

For example, std::vector<Person> people = {Mark, MrMac, Lola, MsWhite, Cindy, Zainab, Mikey, Fred, Zolal} is to be sorted so that teachers will be placed first, then students, and then babies, but with the exception that people with names starting with Z be placed before anyone else, followed by people with age equal to 8. All this is set up by the ordered list:

person.name.at(0) == 'Z',
person.age == 8,
person.type == teacher,
person.type == student,
person.type == baby

So the output gives

Zolal
Zainab (baby)
Cindy
Ms. White
Mr. Mac
Fred
Mark
Mikey (baby)
Lola (baby)

Teachers are supposed to be placed before students, which in turn placed before babies, but Cindy's age is 8, and so is placed before the teachers, and Zolal and Zainab start with Z, so is placed before her. So far so good, but now I want the further sorting result that all people within their subcategories be sorted in their own way, e.g. Zainab should come before Zolal alphabetically, Ms. White should precede Mr. Mac because she is younger, etc... How do I further generalize my customSort function so it carries out those further criteria as well?

View 9 Replies View Related

C++ :: Sort Function For Linked List Program?

Oct 7, 2013

I'm having trouble getting my sort function to work,

void Linkedlist::sort(int num)
{
node *q;
node *a;
int input=num;

[Code].....

I get a crash and I've narrowed it down to the last if statement. Also this function is meant to handle new members after 1 member has been added.

View 7 Replies View Related

C++ :: C Function To Sort A String Based On Delimiter

Apr 7, 2012

I Need to write a function using C wherein I should do the following:

(i) The function will receive a string in a character pointer

(ii) This string will adhere to the following structure:
"Kentucky+New York+Arizona+Nevada"
The number of states can differ from 4 to 50
The delimiter between States can differ from '+' to ',', hence I would like to pass the delimiter to the function.

(iii) This string should then be sorted alphabetically from left to right.
The above example would then become: "Arizona+Kentucky+Nevada+New York"

(iv) This string needs to be returned from the function using a character pointer.

View 3 Replies View Related

C :: How To Write One Binary Tree Function To Sort The Data

Dec 2, 2014

The Problem You are part of a company writing a spreadsheet program. As you know, spreadsheets can be sorted on any column. You're part of the project is to write one binary tree function to sort the data [Hint: use different fields when inserting nodes in the tree.] and a second function to list it in either an ascending or descending sequence. [Note: Each of these functions may actually need to be a set of related functions.]

For sample data you will have a disk file containing information about Shakespeare's plays. Your first function should create a tree based on the sort selected by the user and the second function to display the data in the sequence selected by the user. Regardless of the column being sorted, data in individual records always be displayed in the same line of the output.

Input : Each record will contain the following information: First Performed 9 characters Printed 5 characters Title 26 characters Type 7 characters

Output : Tabular output should be aligned in columns with two spaces between each. All columns should have headings. It should be sorted on the column specified by the user.

Example (This sample data provided so you can test your program.) If the data is:

1595-96 1600 A Midsummer Night's Dream Comedy
1594-95 1623 Two Gentlemen of Verona Comedy
1596-97 1623 King John History
1597-98 1598 Henry IV, Part 1 History
1611-12 1623 The Tempest Comedy
1602-03 1623 All's Well That Ends Well Comedy

[Code]...

Source: [URL]...

Possible outputs are

1 - for a sort by title: First
Performed Printed Title Type
--------- ------- -------------------------- -------
1595-96 1600 A Midsummer Night's Dream Comedy
1602-03 1623 All's Well That Ends Well Comedy
1606-07 1623 Antony and Cleopatra Tragedy
1599-1600 1623 As You Like It Comedy

[Code]....

2 - for a sort by first performed: First
Performed Printed Title Type
--------- ------- -------------------------- -------
1590-91 1594? Henry VI, Part 2 History
1590-91 1594? Henry VI, Part 3 History
1591-92 1623 Henry VI, Part 1 History
1592-93 1623 Comedy of Errors Comedy
1592-93 1597 Richard III History

[Code]....

View 1 Replies View Related

C :: Open Multiple File And Sort Them Using Function Prototype

Apr 9, 2013

I am quite new to C programming. Now facing lots of problem with the code below. I attempt to convert he alphabet sorting into function prototype model but still facing warning during compilation.

Besides, I wish to open multiple file at the same time as well using array looping method, but got no idea to modify it...

[URL] ....

Code:
#include <stdio.h>
#include <string.h>
#define SIZE 255
#define LEN 31

// Function prototype
void alphabetisation (int final, char *webaddress[]);

[Code] .....

View 14 Replies View Related

C++ :: Implement Quick Sort Algorithm Using Recursive Function

Feb 13, 2013

I have written this code to arrange user input array in an order.

//Recursive Quick Sort
#include<stdio.h>
#define ARRAY_SIZE 10
void quick_sort(int array[], int len)
}

[code].....

View 6 Replies View Related

C++ :: Timing Function - Sort Dynamic Array With N Elements

Apr 11, 2014

I'm writing a program that will implement BubbleSort and MergeSort and time them as they sort a dynamic array with N elements. These are the instructions on what my main.cpp file should do.

main.cpp
Include all needed libraries for timing and random number generation while the number of element, N, is less than 100001 repeat the following.

create an array with N (initially 10) random elements
sort the same array with Bubble and Merge sort
time how long it takes each algorithm in microseconds (see example below)
Increase N by a factor of 10 (N *= 10)
Hint: you may want to put your merge sort object on the heap and delete it with every iteration of this loop

And this is what I have so far for my main.cpp

#include <iostream>
#include <sys/time.h>
#include <ctime>
#include <cstdlib>
#include <stack>
#include <iomanip>
#include "BubbleSort.h"
//#include "MergeSort.h"

[Code] .....

One of the errors that I'm running into is that I'm not sure how to correctly call the function I think?

View 3 Replies View Related

Visual C++ :: Writing A Function That Sort Elements Of Array In Numerical Order?

Oct 17, 2014

I have to write a function called sortMe that sorts the elements of an array in numerical order from highest to lowest values (descending order) or vice versa (ascending order).

The assignment asks to: 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.

Header of the function sortMe must be as shown below:

void sortMe(int array[],int sortedIndexes [], int size, char mode)

When mode is 'a', the function sorts the array in the ascending order, and when mode is 'd', the function sorts it in the descending order.

Declare and initialize the array array.

Declare the array sortedIndexes but do not initialize it. You are going to play with the array sortedIndexes in the function sortMe.

EXAMPLE:

int array[5]={3, 5,-1,10,0};
int sortedIndexes[5];
sortMe(array,sortedIndexes, 5, 'a');

After the function call, the elements of the array sortedIndexes should be: 2,4,0,1,3.

notice that the function does not e-arrange the elements in the array.

Code:
#include <iostream>
using namespace std;
void sortMe(int[], int, char);
void main() {
int arr[6] = { 14, -5, 5, 0, 22, -99 };

[code]...

how to use the other array.

View 5 Replies View Related

C++ :: Calling Derived Class Functions In A Function With Parameter Of Base Class

Mar 30, 2013

Say I have 3 classes:

class Player {
public:
virtual func1();

[code]....

Say in my main class, I have a function fight(Player p1, Player p2) and I would like to do something like this in the fight function, given that p1 is the human and p2 is the computer:

//function fight()
fight(Player p1, Player p2) {
p1.func2();
}
//using function fight()
fight(human, computer);

When I compile the program, I got this: error: ‘class Player’ has no member named 'func2()' What can I do to allow p1 to call func2 inside fight()? I'm not allowed to use pointers as the parameter for fight() and have to use the signature fight(Player p1, Player p2).

View 6 Replies View Related

C++ :: Derived Class Not Overwriting Base Class Function - Using Vectors

Feb 4, 2014

So I have a base class, lets call it base. In base I have a virtual function called update(), update just couts "base" then I have a class derived from base called derived;

it has a function called update(), update just couts "derived" then I create a vector called Vec it's initialised like this:

std::vector<base> Vec;

then I add an element into it like this

Derived DerElement;
Vec.push_back(DerElement);

then when I type:

for (int i=0; i<Vec.size(); i++) {
Vec.at(i).Update();
}

It outputs:

Derived DerElement2;
DerElement2.Update();

and it outputs this:

#include <iostream>
#include <vector>
class Base {
public:
virtual void Update() {

[Code] .....

and this is it's output:

Base
Derived
Press any key to continue . . .

View 1 Replies View Related

C++ :: Using Member Function Of A Class In Another Class And Relate It To Object In Int Main

Aug 21, 2013

I am writing a program which is using SDL library. I have two different classes which one of them is Timer Class and the other is EventHandling Class.

I need to use some member functions and variables of Timer in some Eventhandling Class member functions, Although I want to define an object of Timer in int main {} and relate it to its member function that has been used in Eventhandling member function in order that it becomes easier to handle it, I mean that I want to have for example two objects of timer and two objects of Eventhandling class for two different users.

I do not know how to relate an object of a class from int main{} to its member function which is being used in another class member function.

Lets have it as a sample code:

class Timer {
private:
int x;

public:
Timer();
get_X();
start_X();

[Code] ....

View 4 Replies View Related







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