hi,
below is my code for binary search…
inputs----input(stringList),value(string)
output-----pos(string)
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String[] input = IDataUtil.getStringArray( pipelineCursor, "input" );
String value = IDataUtil.getString( pipelineCursor, "value" );
pipelineCursor.destroy();
Integer bin[]=new Integer[input.length];
for(int i=0;i<input.length;i++)
{
bin[i]=Integer.parseInt(input[i]);
}
int val=Integer.parseInt(value);
Integer pos=0;
int low=0;
int high=input.length-1;
while (low <= high)
{
int middle = (low + high) / 2;
if (bin[middle] == val)
{ pos=middle;
}
else if (bin[middle] > val)
{ high = middle - 1;
}
else
{ low = middle + 1;
}
}
String p=pos.toString();
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "pos", p );
pipelineCursor_1.destroy();
#Flow-and-Java-services#webMethods#Integration-Server-and-ESB