Re: [algogeeks] Re: Negative index of array

2011-07-20 Thread pacific :-)
This works.

#include 
#include 

using namespace std;
int main()
{
  map a;
  a[-1] = 0;
  cout<

On Wed, Jul 20, 2011 at 7:50 PM, ankit sambyal wrote:

> You can make the following structure :
>
> #define MAX 100
> typedef struct
> {
>  int count_positive;
>  int count_negative;
> }Element;
>
> typedef Element Map[MAX];
>
> Now you can just create a map as :
> Map map;
>
> Now for every element read, first check whether it is +ve or -ve. Use
> the absolute value of the number read as the key.
> Increment count_positve if key is +ve and increment count -ve if key is -ve
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
regards,
chinna.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Negative index of array

2011-07-20 Thread ankit sambyal
You can make the following structure :

#define MAX 100
typedef struct
{
  int count_positive;
  int count_negative;
}Element;

typedef Element Map[MAX];

Now you can just create a map as :
Map map;

Now for every element read, first check whether it is +ve or -ve. Use
the absolute value of the number read as the key.
Increment count_positve if key is +ve and increment count -ve if key is -ve

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Negative index of array

2011-07-20 Thread SAMMM
You can try this out :---

If  the range of the number are in between -N to +N eg: -10^6 to
+10^6 , then take the the Absolute( Lower bound.) i:e N (10^6) .

For each number add it in the Index [i+N] ..

While printing the value of Number at Index X, Print the value in the
Index [X-N]..


Example:--

List of 6 elements :-   8 4 -3 -10 12 -100   Take N=100

1st  Element  will go to Index-> [8+100]
2nd Element will go to Index-> [4+100]
3rd  Element will go to Index-> [-3+100]=[97]

etc


-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.