C :: Sorting Elements In 2D Array By Their Index

Jun 17, 2013

I need to sort the elements in a 2d array by their index (starting from 1) for example:

Code:
1 5 3
4 7 8
4 10 2

10 is the biggest element and its index is 32, after 10 comes 8 with index 23 etc etc...

Looking for examples for two orders ... By descending and ascending order...

View 5 Replies


ADVERTISEMENT

C :: How To Concatenate Array Index For Same Elements For Specified Range

Apr 22, 2013

Actually i found some mistakes in my post. So here is the modified version. I want to concatenate the indexes of elements of array that has the same value for specific range.In my case the range is 4

Code:

int element[8]={2,2,0,3,3,0,1,2};
col=4;
int rr;
int qq=0;
for (rr=0; rr<col;rr++){
join_tmp[qq]=rr;
while ((element[rr]== element[rr+1]) ) {
join_tmp[qq]= concatenate(rr+1, join_tmp[qq]);
printf("%d
",join_tmp[qq]);
rr++;
}
qq++;
}

Code:

//FUNCTION TO CONCATENATE INTEGER VALUES OF SAME GROUP IN A COLUMN
unsigned concatenate(unsigned x, unsigned y) {
unsigned pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}

Code: I want input like
10
2
3
Instead i get
10
2
34

how can i fix it so it will only iterate to the specific range?

View 2 Replies View Related

C++ :: Sorting Array Of N Given Elements Using Recursion?

Dec 29, 2013

I need to sort an array of n given elements using recursion. What am i doing wrong here?

#include <iostream>
using namespace std;
int i=0, j=1, v[100], n;

[Code].....

View 2 Replies View Related

C++ :: Sorting Array Of 10 Elements Provided By User?

Jan 21, 2014

So I'm trying to sort an array of 10 elements provided by the user. For Example:

Person 1: 5
Person 2: 3
Person 3: 9
etc etc...

I want it to also pair the value with the person. So it should read:

person 3: 9
Person 1: 5
Person 2: 3

Sort the values in descending order.

I can sort the array, but I cant get the Person number to pair with the value...

View 4 Replies View Related

C++ :: Sorting Elements Of Array In Order From Highest To Lowest Values

Jul 6, 2013

I am writing a function called swap that sorts the elements of an array in order from highest to lowest values where they descend and ascend. A particular thing about this function is that swap does NOT re-arrange elements in the array so it just uses a second array of indexes for the elements in the original array and then swap 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. You can declare and initialize the original array without any user input.

For example, int arr[10] = {1, 5, 22, 14, 6, -5, 7, 9, 12, 15 };

Header of the function swap must be as shown below: void swap(int array[],int swapedIndexes [], 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. int swappedIndexes[5];swap(array,swappedInde… 5, 'a');

So far I have this code that randomly generates arrays of 10 elements and I found the max and min, but I am confused on what to do about the swapping part? Also, how to make the numbers ascend or descend in numerical order?? Here is what i have done so far:

#include<ctime>
#include <iostream>
using namespace std;
int min(int [],int);
void max(int [],int , int &);
void main()
{ srand(time(0));
//1-declare

[Code] .....

View 1 Replies View Related

C :: How To Get Index Of Structure Elements

Apr 9, 2013

I want to get the starting index of structure elements, whoz id are 0,1,2,3 Like in below code col_data[0] (starting id=0) col_data[3] (starting id=1) col_data[5] (starting id=2) col_data[8] (starting id=3) Code:

Code:

typedef struct gg{
int id;
int value;
}

[code]....

How can i skip remaining loop iterations when it get that index and will go back to loop again for getting next element index?

View 7 Replies View Related

C++ :: Sorting And Tracking Index Program

Oct 10, 2013

I have been learning c++ for about 1 month. So my problem is that suppose i have array[6]={10,-1,3,54,2,12}

I want to fill new array with {1,4,2,0,5,3}

because -1 is the lowest and its index is 1
2 is the lowest and its index is 4
3 is the lowest and its index is 2
10 is the lowest and its index is 0
12is the lowest and its index is 5
54 is the lowest and its index is 3

I want to sort from lowest to highest but using the index value. Here is what i have but the output i get is {1,4,2,4,5,5}
1,4,2 is right but then its wrong.

#include <iostream>
using namespace std;
void swap(int& v1, int& v2);
int main() {
const int size = 6;
int arry[6]={10,-1,3,54,2,12};
int sortedArry[6];

[Code] ....

View 1 Replies View Related

C++ :: Sorting Elements Of Matrix

Jan 11, 2014

I wrote a code to sort elements of a matrix which are in one row,but it doesn't run well .what should i do??

Code:

#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
int main() {
int i,j,p,q,c1,c2,r1,r2,k,temp=1;
char ans1,ans2,answer;

[Code] ....

View 3 Replies View Related

C :: Sorting Elements In Lexicographical Order

Jan 30, 2013

I have a code right here that i worked on with my teacher. I can say that he did most of the work. Basically i'm sorting elements in a dictionary order.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXWORD 50 // max word size
void swap(char **p, char **q) // Q1: Why do I need a double pointer?

[Code] ....

View 2 Replies View Related

C++ :: Bubble Sorting With User Defined Amount Of Elements

Feb 25, 2014

I am writing some code to bubble sort a list of randoms numbers, 10 at the moment. I want to be able to user input the amount of elements that would be sorted. I think i'd have to use vector instead of arrays, but unsure how to do this. Or, how to be able to change the size of the array.

#include <iostream>
using namespace std;
#define SIZE 10

float numbers[SIZE];
int move_n;

[Code] ....

View 1 Replies View Related

C/C++ :: Take Values From One Array And Searches For Their Index Position In Another Array

Dec 9, 2014

My program takes the values from one array and searches for their index position in another array (linear search algorithm). This is an example of the issue im having(its not part of the actual code below)

a[]={1,2,3,4,5,6}
Arr[]={1,2,2,3,4,5}

If it finds 1 in arr, it returns 0, which is fine but if it finds 2 in arr it return 1 and 1 instead of 1 and 2.

for (int q=0; q=size2;q++) {
int rs=secfunc(array1;size1;array2[q])
if(rs>=0) {
cout<<rs << "";

[Code] .....

View 4 Replies View Related

C :: Array Out Of Index

Apr 17, 2014

I was trying to debug a code which was behaving in an abnormal way

Code:

#define NOOFELEMENTS 32
unsigned char array[NOOFELEMENTS];
unsigned char array1[23];
init() {
for(i=0;i<=32;i++)
{
array[NOOFELEMENTS] = 0
}
}

I could trace the above one of the mistakes where the array initialization is crossing the array limits and writing into array[32] which is not available. My question does it overwrite into array1 as it is declared below array or it can write into any other location.

View 4 Replies View Related

C :: Calloc For Array Of Array With Negative Index

Oct 14, 2014

I have an array of array with negative index. It is an array which has real dimensions [dim_y + 40][dim_x + 40] but the user uses the array like it has dimensions [dim_y][dim_x].

So i see the array's rows lets say from -20 to dim_y + 20 but a user sees only from 0 to dim_y.

First i had global and already defined the dimensions dim_x, dim_y, so i had this:

Code:

int map_boundaries[dim_y + 40][dim_x + 40];
int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20]; In fact, 'map' points to 'map_boundaries' , map[0][0] is map_boundaries[20][20].

I did what is posted in the second post here: Negative array indexing - Everything2.com

I want 'map' to be global. Until now i had defined the dim_y and dim_x so that worked fine.Now i just need to read from a user the dim_x and dim_y.

Until now i have global

Code: int **map_boundaries;

and then in main i use calloc:

Code:

map_boundaries = (int **)calloc(dim_y + 40,sizeof(int*));
for(i = 0; i < dim_y + 40; i++){
map_boundaries[i] = (int *)calloc(dim_x + 40,sizeof(int));}

but i dont know how to declare this line now:

Code: int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20];

View 6 Replies View Related

C/C++ :: Calloc For Array Of Array With Negative Index

Oct 14, 2014

I have an array of array with negative index. It is an array which has real dimensions [dim_y + 40][dim_x + 40] but the user uses the array like it has dimensions [dim_y][dim_x].

So I see the array's rows lets say from -20 to dim_y + 20 but a user sees only from 0 to dim_y.

First I had global and already defined the dimensions dim_x, dim_y, so i had this:

int map_boundaries[dim_y + 40][dim_x + 40];
int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20];

In fact, 'map' points to 'map_boundaries' , map[0][0] is map_boundaries[20][20].

I did what is posted in the second post here: [URL] ....

I want 'map' to be global. Until now i had defined the dim_y and dim_x so that worked fine. Now I just need to read from a user the dim_x and dim_y. Until now i have global

int **map_boundaries;

and then in main i use calloc:

map_boundaries = (int **)calloc(dim_y + 40,sizeof(int*));
for(i = 0; i < dim_y + 40; i++){
map_boundaries[i] = (int *)calloc(dim_x + 40,sizeof(int));
}

But I dont know how to declare this line now:

int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20];

View 3 Replies View Related

C# :: Index Was Outside Bounds Of The Array

May 21, 2014

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mind_Puzzle {
public partial class Form1 : Form

[Code] .....

When i try to start it, it doesn't start or it gives an error on "UsedList[i] = false;".

The error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Mind Puzzle.exe

View 1 Replies View Related

C# :: Array Index Management

Oct 27, 2014

I am suppose to make a value to attach to a array and then have it stop on the last one with an error if it were to go past (done more or less).

Problem is I am suppose to use a int to hold the value of the array and then add 1 each time but my question is, if you were to add another number to increase your current array slot, what would that look like as I image that going array[0] + 1 isn't going to make it array[1].

View 3 Replies View Related

C :: Copy Index Of Characters Of One Array To Another?

Oct 12, 2013

my question is located as a comment beside the last printf ! ? check the comment near the last printf the comment is ==>here i get a sequence of numbers the question is how can i copy this sequence to an array and the print the array out ?

Code:
#include <stdio.h>
#define N 30
#define n 100

[Code]....

here i get a sequence of numbers the question is how can i copy this sequence to an array and the print the array out ?

View 1 Replies View Related

C++ :: Fixing Array Index Out Of Bounds?

Dec 7, 2014

Design and implement the class myArray that solves the array index out of bound problem, and also allows the user to begin the array index starting at any integer, positive or negative. Every object of type myArray is an array of type int. During execution, when accessing an array component, if the index is out of bounds, the program must terminate with an appropriate error message. Consider the following statements:

myArray<int> list(5); // Line 1
myArray<int> myList(2,13); //Line 2
myArray<int> yourList(-5,9); // Line 3

The statement in Line 1 declares list to be an array of 5 components, the component type is int, and the componentst are : list[0], list[1]…list[4]; the statement in Line 2 declares mylist to be an array of 11 components, the component type is int, and the components are: mylist[2],…mylist[12].

This is what I have so far:

#ifndef H_myArray
#define H_myArray
#include <iostream>
using namespace std;
template <class myArray>
class myArray
{
public:
private:
return 0;
};
#endif

View 1 Replies View Related

C/C++ :: Couldn't Find Index Of Array

Feb 12, 2014

I have problem with find the index of the following array.

int minimums[2]={201,201};//first initialize both to greater than maximum allowed

for (int index = 0; index < 200; index++) {
if(find_array[index] < minimums[0]) {
minimums[0] = find_array[index]; //Lowest number

[Code]....

View 14 Replies View Related

C# :: Getting Index Was Outside The Bounds Of The Array Error

Sep 20, 2014

I'm getting "Index was outside the bounds of the array." computerInput.pher[i, 0] = computerInput.availperi[a]; on line 198 but I'm not sure what I need to do in order to correct it. My array seems fine to me and I do see that "i" is showing 0 when debugging and won't change. Either I'm missing something or wrote my array wrong.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestComputerOrder {
class TestComputerOrder {
int style, board, hardDrive;

[Code] .....

View 7 Replies View Related

Visual C++ :: Index Position In Array

Dec 9, 2014

My program takes the values from one array and searches for their index position in another array(linear search algorithm). This is an example of the issue I am having(its not part of the actual code below) :

a[]={1,2,3,4,5,6}
Arr[]={1,2,2,3,4,5}

If it finds 1 in arr, it returns 0, which is fine but if it finds 2 in arr it return 1 and 1 instead of 1 and 2. any thoughts on how to fix this?

Code:
for (int q=0; q=size2;q++) {
int rs=secfunc(array1;size1;array2[q])
if(rs>=0) {
cout<<rs << "
";

[Code] .....

View 12 Replies View Related

C++ :: Writing Strings Into Array Index Within A Function?

Apr 11, 2014

I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.

This is my current program.

Code:
#include<iostream>
#include<string>
using namespace std;
void viewMonth (string month[], int num);
void dayNote (string month[]);
int main()

[Code].....

View 1 Replies View Related

C :: Order Values Of Int Array Only Between Two Index Numbers

Mar 16, 2013

I have 2 arrays, one of doubles and other of integers, the doubles have the result of division of two numbers and the array with the ints have numbers that will refer to another array, but it is not important for this problem.

An example:
doubles array: (12,44;12,44;7,22; 12,44)
ints array: ( 4 , 2 , 3 , 1 )

now using my quicksort function i will organize the array of doubles from the higher to the lower, and the ints array will follow the order of the doubles array, the result is :

doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 4 , 2 , 1 , 1 )

Well, when i have values in the doubles array that are equal, i need to check the ints array and order the ints values, but only the ints that in the doubles array are equals, the final result will be:

doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 1 , 2 , 4 , 1 )

How i can order the ints array only between an interval that is given by the interval of numbers that are equals in the doubles array?

View 4 Replies View Related

C++ :: No Check To Determine Whether The Array Index Is Out Of Bound?

Jun 9, 2013

This is an assignment question In C++, there is no check to determine whether the array
index is out of bounds.Design a class myArray that solves the out-of-bound array index problem and allows the user to begin the array index starting at any integer, positive or negative. Every object of type myArray should be an array of type int.

Part 1 processes only int arrays. Redesign the class myArray using class templates so that the class can be used in any application that requires arrays to process data.

I don't understand the second part. should i just change the array from int to char or something?

View 1 Replies View Related

C++ :: Write Index Of Greatest Element Of Array

Oct 29, 2013

Create a program that will ask the user to input 10 integers of an array the program must write the index of the greatest element of the array

target output

input the integers

the greatest element is 5 and the index is 7

View 3 Replies View Related

C/C++ :: Writing Strings Into Array Index Using Function

Apr 11, 2014

I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.

This is my current program.

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

void viewMonth (string month[], int num);
void dayNote (string month[]);

[Code] .....

How do I make void dayNote function work so I can cin a string into the desired array index?

View 3 Replies View Related







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