Sponsored Content
Top Forums Programming Multidimensional arrays and sort. Post 302492132 by homeboy on Sunday 30th of January 2011 12:33:57 AM
Old 01-30-2011
seems difficult....I wrote a program to illustrate the situation of a two dimensions array,more dimensions will be more difficult to implement.
Code:
typedef struct {
	int a;
	int b;
}EMBED;

bool my_sort(EMBED a,EMBED b){
	return a.b > b.b;
}

int main()
{
	int a[10][2];
	EMBED embed_a[10];

	srand(time(NULL));	
	
	for(int i=0;i<10;i++)
		for(int j=0;j<2;j++)
			a[i][j] = rand()%200;
			
	for(int i=0;i<10;i++){		
		embed_a[i].a = a[i][0];
		embed_a[i].b = a[i][1];
	}
	
	vector<EMBED> vec(embed_a,embed_a+10);
	sort(vec.begin(),vec.end(),my_sort);

	for(int i=0;i<10;i++){
		for(int j=0;j<2;j++)
			cout<<a[i][j]<<" ";
		cout<<endl;
	}
	cout<<"============AFTER SORTING==============="<<endl;
	for(vector<EMBED>::const_iterator iter = vec.begin();
								iter != vec.end();iter++)
		cout<<iter->a<<" "<<iter->b<<endl;

	return 0;
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

multidimensional arrays

I have a file that's logically in the form of a multidimensional array with an unknown number of records in the file. The file looks like this: name1 data1 name2 data2 name3 data3 ... nameN dataN How do I load this file into an array for processing, while... (2 Replies)
Discussion started by: leslie02
2 Replies

2. Shell Programming and Scripting

awk multidimensional values

Hello All, Here is my input file content and i am trying to write an awk file that produces the output as shown below. i tried with my little knowledge but was not successful. Input File content: ID COL1 COL2 COL3 1002 1 val21 val31 1002 2 val22 val32 1002 3 val23 val33... (2 Replies)
Discussion started by: forumthreads
2 Replies

3. Shell Programming and Scripting

multidimensional arrays using awk

i'm trying to use awk to count a listing similar to the following and get a report of the listing similar to the one below it. y,pizza n,pizza y,pizza y,pizza n,tomato n,tomato y,cheese y,cheese n,cheese report ---- pizza,3,1 tomato,0,2 cheese,2,1 (1 Reply)
Discussion started by: multimulti
1 Replies

4. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

5. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

6. Shell Programming and Scripting

Multidimensional arrays

Hi Experts, I'm a newbie.....multidimensional arrays in shell scripts is possible??? If so, can anyone guide me with an example.....and also can anyone tell me, how we can create a table like ouput format in shell script....the output should look like this one: 1 2 3 4 5 6 6 5 4 3... (4 Replies)
Discussion started by: kritibalu
4 Replies

7. Shell Programming and Scripting

How do I sort two arrays using awk?

Hi How do I sort two arrays in a ascending order? I'm just doing this to teach myself a book my dad got me on unix. The arrays are A and B and both are including values taken from a file input by the user. How do I arrange the contents of both arrays so that they are both ordered from... (3 Replies)
Discussion started by: razrnaga
3 Replies

8. Shell Programming and Scripting

Multidimensional arrays Shell Programming and Scripting

I have two files: file-1 is a list of number of interfaces in the switch and file-2 have VLAN-ID , VLAN-NAME , Interface belong to that VLAN like this: file-1: 1/1 1/2 1/3 1/4 1/5 . . file-2: 1,"vlan-wifi",1/1,1/7,1/8 (9 Replies)
Discussion started by: SULTAN01
9 Replies

9. Shell Programming and Scripting

Multidimensional array

I am learning about bash system variables, such as $ , @ and #. I have this piece of script implementing an array and it is doing its job just fine. This is not the only array I will be using. Just for ease of maintenance and more coding I would like to have the arrays in two dimensional... (4 Replies)
Discussion started by: annacreek
4 Replies

10. Shell Programming and Scripting

Sort multidimensional Array

Hello I have a problem. I create a Multidimensional Array Like this: ENTRY="$kunnum-$host" ENTRY="$host" ENTRY="# $3" for key in "${!ENTRY}"; do ENTRIES=${ENTRY} # INDEX=IP(5) donedeclare -p declare -A ENTRIES=(="unas15533" ="unas" ="# RDP-Terminal 2"... (12 Replies)
Discussion started by: Marti95
12 Replies
mouse_getposition_6d(3) 					Svgalib User Manual					   mouse_getposition_6d(3)

NAME
mouse_getposition_6d, mouse_setposition_6d, mouse_setrange_6d - provide an interface to 3d mice SYNOPSIS
#include <vgamouse.h> void mouse_getposition_6d(int *x, int *y, int *z, int *rx , int *ry, int *rz); void mouse_setposition_6d(int x, int y, int z, int rx , int ry, int rz, int dim_mask); void mouse_setrange_6d(int x1, int x2, int y1, int y2, int z1 , int z2, int rx1, int rx2, int ry1, int ry2 , int rz1, int rz2, int dim_mask); DESCRIPTION
These routines provide the same function as mouse_getx(3), mouse_gety(3), mouse_setxrange(3), mouse_setyrange(3), mouse_setposition(3), and mouse_getx(3), except that they work in all six dimensions, x, y, z, and rotations about those axes. For mouse_getposition_6d(), NULL pointers may be passed for any coordinate you don't care to know about. Those dimensions will be ignored. mouse_setposition_6d() and mouse_setrange_6d() take an additional argument called dim_mask, which should be an logical or of the following: MOUSE_XDIM, MOUSE_YDIM, MOUSE_ZDIM, MOUSE_RXDIM, MOUSE_RYDIM, or MOUSE_RZDIM. MOUSE_2DIM, MOUSE_3DIM, MOUSE_6DIM can be used as shorthand for the XY, XYZ, or XYZRxRyRz dimensions. The position or ranges will only be set if that dimension is included in dim_mask. The 6d mouse routines can be used safely with any mouse type, including standard 2D mice. When used with mice that support fewer than six axes, the other coordinates will always return zero (or whatever value you set them to). SEE ALSO
svgalib(7), vgagl(7), libvga.config(5), eventtest(6), mouse_close(3), mouse_init(3), mouse_setposition(3), mouse_getx(3), mouse_setscale(3), mouse_setwrap(3), mouse_setxrange(3), mouse_update(3), mouse_waitforupdate(3), vga_setmousesupport(3), mouse_seteven- thandler(3), vga_waitevent(3) AUTHOR
This manual page was edited by Michael Weller <eowmob@exp-math.uni-essen.de>. The exact source of the referenced function as well as of the original documentation is unknown. It is very likely that both are at least to some extent are due to Harm Hanemaayer <H.Hanemaayer@inter.nl.net>. Occasionally this might be wrong. I hereby asked to be excused by the original author and will happily accept any additions or corrections to this first version of the svgalib manual. Svgalib (>;= 1.2.11) 27 July 1997 mouse_getposition_6d(3)
All times are GMT -4. The time now is 09:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy