Selection sorting a 2D array . Let's say i have an array like
1 2 3 4 //4 elements 1 2 // 2 elements 1 2 3 4 5 //5 elements 1 2 3 //3 elements 1 //1 element
And I want to do a selection sort it in descending order which the row with 5 elements will come first then 4 then 3 and so on. So that it would look like this
1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Code: void selectionSortDescending(int list[MAX_ROW], int size){ int temp; int walk; int curr; int large; // index of the largest element
i have a matrix containing a lot of points and each point has its coordinates x and y. That is a nx2 size array. I want to sort it according to the first column ascending, with x coordinates. For points that have the same x coord i would like to sort according to y coord. Here is what i did and i cannot get a good result.
Code:
#include <stdio.h> #include <stdlib.h> int main(){ int a[5][2] = {{1,0}, {4,2}, {2,4}, {8,6},{4,8}}; int temp=0; int i=0; int j=0;
i need to print the names as they appear in the original file, print the info of the person with the highest distance, print the info sorted by ascending ID number, and print sorted by name alphabetically. the first two parts work fine but sorting by ID and Name dont work.
Here is what I have, I have a 1D Array being added to a 2D Array and I need to Sort them by value value 3 in the 2D Array, while maintaining a specific amount. Here is what I have so far:
I am thinking bubble sorting but I remember reading about something faster. Unfortunately I can't find it on the web. The idea is that there will be always 10 Values and 4 Columns on the 2D Array. [The 11th Row being empty at the end of it.
I have an algorithm and I want to make it as efficient as possible. Basically it just involves putting numbers in order. I have two options, but which one would be more efficient:
1. Using a doubly linked list. Every time a user wants to add a new number, the algorithm will start searching the correct place for the number from the beginning of the list. This is efficient per se, but once there are about a million numbers and a number has to be put in at the end of the list, the algorithm must go through all the 999 999 numbers before it.
2. Using a container to store all the numbers first, then sorting the numbers. In this case, adding all the numbers is fast, but the actual sorting will take a long time.
Which option would be more efficient? I was thinking of using maybe merge sort or quick sort in option 2. Yes, I'm aware I could just use vector and sort, but that's not my goal here.
I have two arrays of characters that I want to combine and sort according to an internal variable (init) using a forward-iterating linked list. The two arrays must stay separated, as one of the arrays (the enemies) is contained within the object (encounter), the other is passed in via pointers (the players). The array inside the object will be destroyed later (when the encounter is over and the enemies are hopefully dead) while the one that is passed in must survive to be passed into other objects at a later time (the next encounter). My thought is to sort each array by linked list separately first, then iterate through and combine the two lists, But how to do this and no support IRL.
// DECLARATION OF CLASSES // class character{ public: character(); // Constructor
I should sort an array of mixed float and integer numbers by merge method, and using the pointers to sort that mix array. how to use pointers to sort those different type of data.
Were supposed to be able to sort an array which is user input, but the first number they input is supposed to be the length of the array, and everything after that is the actual array.
Here is my code:
#include <iostream> #include <iomanip> using namespace std; int main() { int size; int list[80]; bool isSorted (const int list[], int size);
[code]....
I'm stuck on how I'm supposed to use the first digit of input for the array size.
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
I need to find the Mean, median, mode, and make a histogram of a 99 value array. How ever my sorting function is not sorting the array at all how can I fix this.
Code: //prototype void improvedbubblesort (struct team Table[]); //this is defined out side of main
[Code]....
the whole code is very long but can post if necessary . Basically i get no errors in this but its not sorting them . Think its in the way i pass the array of struct .
I am trying to read information in from a file, each line of which contains a name in the form 'last, first middle'. I can successfully open the file and read it into an array that is roughly 2500 string in size. The problem comes when I try to sort the array into alphabetical order. I am using a sorting algorithm that we were instructed to use, found in our book. It is shown in the code. I would add the file that needs to be opened, but it is a few thousand lines long.
The error I am getting is: Unhandled exception at 0x00A28628 in PeopleSearch.exe: 0xC0000005: Access violation reading location 0x00CC400C.
and I know it has to do with the sorting algorithm from using break points and running the program with that section commented out. I am stumped to why it is giving this error, as it seems that it is trying to access the array outside of the bounds of the array, but it shouldn't be