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
ADVERTISEMENT
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
May 20, 2014
im trying to make a statistics program and i have an array holding all the users numbers. The array has 10 elements and i was wondering how i could put these elements in order from smallest to largest.
View 18 Replies
View Related
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
Dec 10, 2014
I want to write a programm that will reverse the order of the numbers in an array (e.g. as an input 1,2,3.5,4 and as an output i want 4,3.5,2,1) . But i have to problems:
1) I do not know how to properly change the type of a numbers inside an array from int to float or double, changing int to float in front of the a[10], does not change anything instead the code does not want to compile then.
2) I also want to make an array of a number of elements typed by a user with use of a "do" loop and how to put this parameter in the code.
Here is my code:
Code:
// ConsoleApplication3.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[]) {
int a[10], i, n;
int pom;
do {
printf("number of elements in an array a: n = ");
[Code]...
View 5 Replies
View Related
Jan 30, 2015
understand the details of what this function actually do?
View 7 Replies
View Related
Oct 29, 2014
I am trying to write a program which will sort an array of numbers into ascending order, here is my code
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int array[]={1, 5, 17, 3, 75, 4, 4, 23, 5, 12, 34, 34, 805, 345, 435, 234, 6, 47, 4, 9, 0, 56, 32, 78};
[Code] .....
This compiles fine but when I run the .exe for the first time an error message comes up saying program has stopped working. If I run the program again without recompiling it seems to work as expected.
View 2 Replies
View Related
Sep 6, 2013
How can I use one index to iterate between all the values
for example:
//I defined
vector<typeA> VA(XD,typeA());
vector<typeB> VB(XD,typeB());
//then the standard method to iterate is:
for(vector<typeA>::Size_type i=0; i<VA.size(); i++) {
VA[i].functionA();
VB[i].functionB();
}
the other way, use int,
//I defined
vector<typeA> VA(XD,typeA());
vector<typeB> VB(XD,typeB());
//then the standard method to iterate is:
for(int i=0; i<VA.size(); i++) {
VA[i].functionA();
VB[i].functionB();
}
none of above make me feel formal...
View 7 Replies
View Related
Apr 4, 2013
I have to be more code specific (I usually try to abstract my code). As you can see I use a lot Qt classes... however they work very similar to standard libraries, so it should be not a problem to look at this question.
class FrameManager {
QList<FRAME> frameData;
public:
int frameID(int grpno, int imgno);
};
[Code] ....
Now I know the example search only the ID and doesn't allow the access of the actual data... this is not the question.
The problem is... I will need to define an AnimationManager class that will collect sequence of frames (identified by the unique couple of value) in animations... so it will need to use a massive search of item from the couple of value (and not ID, unluckly)
I fear if I use an approach similar to the one written in the example (search from the start to the end until the element is found) can be very unefficient.
In the same time the AnimationManager should always know if frame exist or not (if not exist an invisible image will be shown) and if in the meantime changed.
Another problem is that I cannot order the data sequence inside FrameManager (becouse it is expected to mantain the original order, even when it is chaotic).
I tried to take a look around QMap (or std::map) but it is not clear at all how the optimiziation works and how I can use it in my case
I tried also to take a look at the "hash" concept, but for me it is too complex to understand deeply.
So... I am feeling like I am entrapped... I am unable to find a good "exit"...
View 8 Replies
View Related
Mar 18, 2013
im using a for loop to find the index values of the tied high scores and store them into string list then reference list in the second for loop to output it to screen however it isnt letting me use an array with index i as an index its self.
void printHighest(Student s[], int length){
int index;
string list[10];//you're never going to have more than 10 people with a tieing highscore.
index = findMax(s, length);
[Code] ....
For the time being I simply removed the idea of string list and just put the contents of the second for loop into the if statement above it. However, I am still curious as to if I can reference an index of an array in an index of another array.
View 1 Replies
View Related
Apr 20, 2014
I'd like to do a MergeSort with sentinels and order the pointers, not the values!
#include <iostream>
#include <limits>
using namespace std;
void
stampa (int *n) {
int i;
for (i = 0; i < 10; i++) {
[Code] .....
View 9 Replies
View Related
Apr 12, 2014
My game is a sort of RPG with stats, money etc. I just recently added a save/load system using writing to a file. I initially got writing to a text file to work, then I got loading to work too.I eventually was able to read numbers from the file and assign them to integer variables in order.
My issue was I wanted to check if a save file existed, if it did, load it up, if it did not, go to character creation. I had a lot of trouble with this and after trying different code snippets to work I finally got it to check if a file existed, and execute the appropriate code.
My issue now is my code USED to go through each entry and assign variables in order.
Like the first number in the text file would be for the variable money, and it would read it, assign to to int money and scroll to down to the next variable for player strength, assign to to playerstr variable and so on. After making the tweak for loading it no longer functions like this, and makes the last entry in the text file the value for everything.
Here's my code:
Save Code:
{
ofstream savegame;
savegame.open("C:/Sounds/savegame.dat", ios::trunc);
savegame << money << endl;
savegame << playerstr <<endl;
[Code]....
I barely get how this code works, how can I tweak it to go through the file in order and assign variables one at a time?
At the current moment, it assigned the playerstr value to both money and playerstr int. But the save file being created lists the correct values in order.
View 5 Replies
View Related
Mar 13, 2014
SO lets say I have a file that says
10 tennent
9 Eccleston
12 Capaldi
11 Smith
How do I get the number's in order but not changing the name it goes with? SO here is how I started it
# include <iostream>
# include <fstream>
# include <sstream>
# include <set>
# include <list>
# include <string>
# include <cctype>
# include <vector>
[Code] ....
View 12 Replies
View Related
Mar 17, 2015
I am currently writing a program and am having some trouble figuring out how to get the order correct in the output.
Here is my code:
using System;
using System.Collections;
using System.Text;
namespace The_Last_Survivor {
class Program {
static void Main(string[] args) {
[code].....
The output I need to have is:
Actors Count Audition Order
1 1 1
2 1 1 2
2 2 2 1
3 1 1 2 3
3 2 2 1 3
3 3 3 1 2
4 1 1 2 3 4
4 2 2 4 3 1
4 3 3 2 4 1
[code].....
Right now the numbers are just printing in order 1-9 and not changing.
View 7 Replies
View Related
Feb 19, 2014
Write a program that orders three double numbers by increasing value. The program should include a function named sort3 that takes three double * arguments (pointer to double). The function prototype is void sort3(double *x, double *y, double *z); The function should reorder the values pointed to by its arguments so that after the call sort3(&x, &y, &z); the numbers satisfy . Your program should input data and print results using the following format:
Enter three numbers: 4.7 1.4 3.2
The ordered sequence is: 1.4 3.2 4.7
And here is my program: C code - 32 lines - codepad
I am getting a lot of errors when I run it through GCC. I can only use pointers.
View 4 Replies
View Related
Nov 9, 2014
I have to put these numbers in ascending and descending order . The interesting point of the function is that sortMe does 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. I'm not sure why the function is working, even though I called it in main.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void sortMe(int array[], int sortedIndexes[], int size, char mode);
char option;
const int SIZE = 5;
[Code] .....
View 7 Replies
View Related
Aug 13, 2014
Write a program that prompts the user to enter three integer values, and then outputs the values in numerical sequence separated by commas.
So, if the user enters the values 10 4 6, the output should be 4, 6, 10.
If two values are the same, they should just be ordered together.
So, the input 4 5 4 should give 4, 4, 5.
Code:
#include "std_lib_facilities.h"
int main()
{
cout << "Enter three integers, separated by space: ";
int a, b, c, temp1 = 0, temp2 = 0;
cin >> a >> b >> c;
[Code] ....
My first solution has a bug, so here's the corrected solution, written using only features I have learned in the first three chapters:
Code:
#include "std_lib_facilities.h"
int main()
{
cout << "Enter three words, separated by space: ";
string a, b, c, temp;
cin >> a >> b >> c;
[Code] ....
View 5 Replies
View Related
Sep 7, 2014
What kind of code should i use for sorting numbers in both ascending and descending order? I don't know how to use bubble sorting either, is there another easy way to sort this out?
View 3 Replies
View Related
Feb 9, 2013
I want to store a very small number - too small for even a long double. However, I don't need the number to be stored very precisely - in fact, all I really need is the order of magnitude of the number. For example, the number 5.205849034425 X 10^-381 can just be stored as an integer of -381 for my purposes. I don't really care about the precision of the 5.205849034425 part.
The reason I get this very small number, is because I am multiplying together thousands of numbers, all of which are around 0.0001 in value. So, one way to do this would be to store all these individual values as simply their order of magnitude (e.g. -4) and then instead of multiplying the numbers, I would just add up their orders of magnitude. However, I am wondering whether there is a way in C++ to do this without me having to change the way I store my data - I still would like to keep the original values if possible.
View 2 Replies
View Related
May 12, 2013
So if i write a Loop to calculate Prime Numbers in order, is there any way possible for this to happen in a shorter period of time.
The loop that i constructed took about 11hrs on a Win 7 2GB ram machine to calculate about 150,000 primes, could this be done any faster................
View 14 Replies
View Related
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
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
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
Oct 19, 2014
Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.
In order to fix this error: [URL]...
I had to change my array initialization to one with a star in front of it:
char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
to:
char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
I also changed my 2nd array to one with a star in front of it: char *a2[20];
What does this mean exactly? Putting a star in front of an array?
Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:
cin>>a2[i];
View 3 Replies
View Related
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
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