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;
I've been trying to get my matrix multiplication program to run a few different ways. My assignments wants me to run it statically using chunks, but we're not supposed to use OpenMPs scheduler. So I'm not sure how that's possible. And secondly, we have to run it dynamically using locks/unlocks.
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.
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 */
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?
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
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?
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);
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.
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.
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:
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?
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.
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
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...
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
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.
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() {
I want to set an integer to zero when it easy equal to another integer, but it seems that the program for some reason won't set the integer to zero. Here is the example of that code:
#include <iostream> using namespace std; int main () { int n = 2; int r = 2; if(n==r) n++; r*0; cout << " n is " << n << endl; cout << " r is " << r << endl; }
What am I doing wrong, it should say that "n is 3" and "r is 0".