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
wresize(3NCURSES)                                                                                                                wresize(3NCURSES)

NAME
wresize - resize a curses window SYNOPSIS
#include <curses.h> int wresize(WINDOW *win, int lines, int columns); DESCRIPTION
This is an extension to the curses library. It reallocates storage for an ncurses window to adjust its dimensions to the specified values. If either dimension is larger than the current values, the window's data is filled with blanks that have the current background rendition (as set by wbkgdset) merged into them. RETURN VALUE
The function returns the integer ERR upon failure and OK on success. It will fail if either of the dimensions less than or equal to zero, or if an error occurs while (re)allocating memory for the window. NOTES
The only restriction placed on the dimensions is that they be greater than zero. The dimensions are not compared to curses screen dimen- sions to simplify the logic of resizeterm. The caller must ensure that the window's dimensions fit within the actual screen dimensions. SEE ALSO
resizeterm(3NCURSES). AUTHOR
Thomas Dickey (from an equivalent function written in 1988 for BSD curses). wresize(3NCURSES)
All times are GMT -4. The time now is 10:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy