//Filename: Search3.html
<!--Html program to read search key-->
<HTML>
<HEAD>
<TITLE>Sorting and Searching</TITLE>
</HEAD>
<BODY>
<H1>Program to sort list of names and search for key</H1>
<FORM ACTION="Search3.jsp" METHOD="POST">
Please enter your the search key:
<BR>
<input NAME="text1" type="text">
<BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</BODY>
<HTML>
//Filename:Search3.jsp
<!--03. Program to search the given name using binary search.-->
<html>
<body>
<%@ page import="java.io.*,java.util.*"%>
<%
final String str[]={"Pineapple" , "Orange" , "Apple", "Grapes", "Banana"};
String key=request.getParameter("text1");;
int index = -1,i;
int len=str.length;
Arrays.sort(str);
Arrays.toString(str);
index = Arrays.binarySearch(str, key);
%>
<h3>The sorted list of names:<h3>
<%
for(i=0;i<len;i++)
{
out.println(str[i]);
%>
<BR>
<%
}
%>
<BR>
<%
if(index>-1)
{
out.println("Key found at location "+(index+1));
}
else
{
out.println("Key not found!");
}
%>
</body>
</html>
<!--Html program to read search key-->
<HTML>
<HEAD>
<TITLE>Sorting and Searching</TITLE>
</HEAD>
<BODY>
<H1>Program to sort list of names and search for key</H1>
<FORM ACTION="Search3.jsp" METHOD="POST">
Please enter your the search key:
<BR>
<input NAME="text1" type="text">
<BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</BODY>
<HTML>
//Filename:Search3.jsp
<!--03. Program to search the given name using binary search.-->
<html>
<body>
<%@ page import="java.io.*,java.util.*"%>
<%
final String str[]={"Pineapple" , "Orange" , "Apple", "Grapes", "Banana"};
String key=request.getParameter("text1");;
int index = -1,i;
int len=str.length;
Arrays.sort(str);
Arrays.toString(str);
index = Arrays.binarySearch(str, key);
%>
<h3>The sorted list of names:<h3>
<%
for(i=0;i<len;i++)
{
out.println(str[i]);
%>
<BR>
<%
}
%>
<BR>
<%
if(index>-1)
{
out.println("Key found at location "+(index+1));
}
else
{
out.println("Key not found!");
}
%>
</body>
</html>
No comments :
Post a Comment