Hi,
This one is quite easy. You have to calculate the number of one's before
every zero and add them up. That's it.
public class Test1 {
public void printArray(int[] tmpArr) {
for (int i : tmpArr) {
System.out.println(i);
}
}
public int calculateMinSwaps(int[] tmpArr) {
int minSwaps = 0;
int
http://stackoverflow.com/q/11240022/1081340
--
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.
Hi
Question as in subject
*No extra spaceĀ (can use one extra space)-O(1) max
*No order change allowed
example:
input : 1,-5,2,10,-100,-2
output: -5,-10,-100,1,2
input : -1,-5,10,11,15,-500,200,-10
output : -1,-5,-10,-500,-10,10,11,15
Thanks
Raghavn
--
You received this message because you
This link should help
http://stackoverflow.com/questions/5667793/how-does-a-read-write-mutex-lock-work?rq=1
-mithun
On Fri, Jun 29, 2012 at 7:30 AM, bharat b bagana.bharatku...@gmail.comwrote:
class lock
{
enum{read, write,free}status;
};
By default, make status value as free.
Based
first search for node where abc ends i.e say func Search() will return
node whose
node-ch='c';(last character of input abc)
then pass this node to following algo :-
this is just a code sketchso you can add boundary conditions to
it..(if i miss it)
print(node *root,int j)
{
if(!root)
duplicate of a previous post.Kindly refer to that post.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com
On Fri, Jun 29, 2012 at 10:41 AM, raghavan M
peacelover1987...@yahoo.co.inwrote:
Hi
Question as in subject
*No extra space (can use one extra
one can modify dutch national flag algo for two colors(2 types positive n
negative)
--
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
Quick sort partition routine variation.
On Fri, Jun 29, 2012 at 3:06 PM, Ravi Ranjan ravi.cool2...@gmail.comwrote:
one can modify dutch national flag algo for two colors(2 types positive n
negative)
--
You received this message because you are subscribed to the Google Groups
Algorithm
Doubt, very trivial though:
#includestdio.h
int main()
{
int x=3;
switch(x)
{
case 1:
x=1;
break;
case 2:
x=2;
break;
case 3:
x=3;
break;
default:
x=0;
break;
case
the cases are simple lables they have nothing to do with the flow of
program.
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com
On Fri, Jun 29, 2012 at 3:14 PM, adarsh kumar algog...@gmail.com wrote:
Doubt, very trivial though:
#includestdio.h
int main()
{
The main idea of this question is *not to change order of occurrence.Dutch
National flag other swapping like quick sort will change the order of
occurrence of number
try yourself with simple example for proof.
From: Ravi Ranjan ravi.cool2...@gmail.com
To:
This is a variant of that one
From: saurabh singh saurab...@gmail.com
To: algogeeks@googlegroups.com
Sent: Friday, 29 June 2012 3:05 PM
Subject: Re: [algogeeks] MS Question: Segregrate positive and negative nos in
array without changing order
duplicate of a
your program enter at
case 3:
after that it kept falling in next cases as well hence x was assigned
values
x=0,
x=0,
and x=4 at the end.. and then exit the switch case...
use print after every assignment u'll see that...
On Fri, Jun 29, 2012 at 3:16 PM, saurabh singh saurab...@gmail.com
case 1: , case 2 : , case 3 , case 4 ...etc etc are just labels...
so switch(x) just jumps to that case x and then move downward. so if you
dont use break..it will keep checking following cases.
On Fri, Jun 29, 2012 at 3:14 PM, adarsh kumar algog...@gmail.com wrote:
Doubt, very trivial
+1 atul
If a matching label is found, execution proceeds from there. Control then
passes down through all remaining labels within the switch statement.
On Fri, Jun 29, 2012 at 3:28 PM, atul anand atul.87fri...@gmail.com wrote:
case 1: , case 2 : , case 3 , case 4 ...etc etc are just
please someone explain lvalue and rvalue with example...
for llvalue..please explain ++x++ also..
thanks.
--
Vindhya Chhabra
--
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
l-values(left, literal meaning) appear on the lhs of a statement, and
r-values vice versa. Essentially, l-values are identifiers. The memory
location that will be thereby allocated can vary for r-values. Put in
short, all l-values are r-values but not all r-values are l-values.
And ++x++, will
R-value - Contents of memory location ( ie value stored in that memory
location )
L-Value - Name of that memory location
suppose , int i=9; than here* r-value is 9* and* l-value is i* .
Taking *++x++ ..*
As Postfix ( ++ ) is having higher precendence over Prefix( ++ ) so Postfix
will be
calculate the balance factor for all nodes and find any node with factor
1 or factor -1 and perform AVL rotation from that node
--
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.
l value - address
r value - content of variable(value)
ex-
x=2
x has value and address
but 2 has only value
cout++x++
I think this will result into l error .
PRAVEEN RAJ
DELHI COLLEGE OF ENGINEERING
--
You received this message because you are subscribed to the Google Groups
Algorithm
2 malloc():
int **a=(int **)malloc(sizeof(int *)*nrows);
for(i=0;inrows;i++)
a[i]=(int *)malloc(sizeof(int)*ncols);
using only 1 malloc:
int **a=(int **)malloc(sizeof(int *)*nrows+(nrows*ncols)*(sizeof(int)));
for(i=0;inrows;i++)
{
a[i]=(int*)(a+nrows+i*ncols);
}
On Fri, Jun 29, 2012 at 4:46 PM,
Given an integer expression in a prefix format (i.e. the operator
precedes the number it is operating on) , print the expression in the
post fix format .
Example: If the integer expression is in the prefix format is *+56-78,
the postfix format expression is 56+78-*. Both of these
correspond to
@all thanks
On Fri, Jun 29, 2012 at 6:33 PM, Atul Singh atulsingh7...@gmail.com wrote:
R-value - Contents of memory location ( ie value stored in that memory
location )
L-Value - Name of that memory location
suppose , int i=9; than here* r-value is 9* and* l-value is i* .
Taking
If the order is important then I think we can use any stable sorting
algorithm with the following comparison function
int compare (int a ,int b)
{
if((a0b0)||(a0b0)) return 0;
else return ab;
}
On Fri, Jun 29, 2012 at 3:37 PM, raghavan M
peacelover1987...@yahoo.co.inwrote:
This is a variant of
@saurabh please provide the link to the post you are mentioning
On Fri, Jun 29, 2012 at 8:38 PM, Bhaskar Kushwaha
bhaskar.kushwaha2...@gmail.com wrote:
If the order is important then I think we can use any stable sorting
algorithm with the following comparison function
int compare (int a
@bhaskar:- please explain stable sorting algorithm you would use(as mainly
all of them require extra space)
@sourabh:- that previous post discussion does't lead to any correct soln
On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha
bhaskar.kushwaha2...@gmail.com wrote:
@saurabh please provide
+1 naveen
On Thursday, June 28, 2012 8:29:26 PM UTC+5:30, Navin Gupta wrote:
Keep two pointers - one at start of the array and other at end of the
array
Now current points to start of the array
If current is negative , increment current
If current is positive , swap it with the element
Hi,
this can be done by simple modification in bubble sort :
void inplace_pos_neg(int pdata[],int sz)
{
bool changed=false;
do
{
changed=false;
for(int i=1;isz;i++)
if(pdata[i-1]0 pdata[i]0)
{
swap(pdata[i-1], pdata[i]);
changed=true;
}
}while(changed);
}
void test_inplace_pos_neg()
{
int
I think just reversing the prefix notation converts it to postfix notation
On Fri, Jun 29, 2012 at 7:46 PM, Gobind Kumar Hembram
gobind@gmail.comwrote:
Given an integer expression in a prefix format (i.e. the operator
precedes the number it is operating on) , print the expression in the
@Hassan I think your algo will take time O(n^2) in worst case which occurs
when all elements are negative except the last one
@everyone Can we solve this problem in linear time?
On Fri, Jun 29, 2012 at 9:10 PM, Hassan Monfared hmonfa...@gmail.comwrote:
Hi,
this can be done by simple
@Navin: Try this with {1,-1,2}. current points to the 1 and end points to
the 2. Since 1 is positive, the algorithm swaps the 1 and the 2, giving
{2,-1,1}. Then it decrements current to point outside the array and end to
point to the -1. How can this be right?
Dave
On Thursday, June 28, 2012
@bhaskar ur algo fails on this case (5+3)-(2+(3/6))
-+53+2/36
63/2+35-+
showing that 6/3 but actually it is 3/6
so i think it could be done by folowing algo
make a binary tree of given expression in O(n) then do postorder traversal
take O(n) so problem can be solved in O(n). and take O(2*n+1)
oh bhai mere. kewal preorder use karke kaise tree bana dega???
On Fri, Jun 29, 2012 at 11:23 PM, amrit harry dabbcomput...@gmail.comwrote:
@bhaskar ur algo fails on this case (5+3)-(2+(3/6))
-+53+2/36
63/2+35-+
showing that 6/3 but actually it is 3/6
so i think it could be done by
convert prefix to infix,then convert infix to postfix.Now, to convert
prefix to infix, push numbers in one stack and operators in other.Then use
thishttp://www.velocityreviews.com/forums/t445633-prefix-to-infix-conversion.html
algo
to perform this.Then do the same for infix to postfix.It works
reverse the prefix notation and then reverse each continuous occurence of
operands
On Sat, Jun 30, 2012 at 12:50 AM, Abhishek Sharma abhi120...@gmail.comwrote:
convert prefix to infix,then convert infix to postfix.Now, to convert
prefix to infix, push numbers in one stack and operators in
example
-+53+2/36
step 1: 63/2+35+-
step 2: 36/2+53+-
On Sat, Jun 30, 2012 at 1:55 AM, Bhaskar Kushwaha
bhaskar.kushwaha2...@gmail.com wrote:
reverse the prefix notation and then reverse each continuous occurence of
operands
On Sat, Jun 30, 2012 at 12:50 AM, Abhishek Sharma
36 matches
Mail list logo