20202306 Experiment 7 search and sort

#20202306 2021-2022-1 data structure and object oriented programming experiment 7 report

Course: programming and data structure
Class: 2023
Name: Li Jincheng
Student No.: 20202306
Experimental teacher: Wang Zhiqiang
Experiment date: November 12, 2021
Compulsory / elective: compulsory

##1. Experimental contents

  1. Define a Searching and Sorting class, implement the linearsearch and selectionSort methods in the class, and finally complete the test.
    At least 10 test cases are required to submit the test case design (normal, abnormal, boundary, positive sequence and reverse sequence). The use case data shall include the last four digits of their student number
    Submit operation result diagram.

  2. Refactoring your code
    Put Sorting.java Searching.java into cn.edu.besti.cs2023. (initials + four student numbers) package (for example: cn.edu.besti.cs1823.G2301)
    Put the test code in the test package
    Screenshots of recompilation, running code, submitting compilation and running (IDEA and command line)

  3. reference resources http://www.cnblogs.com/maybe2030/p/4715035.html , learn various search algorithms, Supplement Search Algorithms in Searching and test them
    Submit screenshot of operation results

  4. Implement sorting methods, etc. (at least 3)
    Test the algorithm implemented (normal, abnormal, boundary)
    Submit screenshots of running results (if multiple sorting algorithms are written, full marks can be given as appropriate even if three sorting programs are defective)

  5. Write Android programs to test various search and sorting algorithms
    Submit operation results
    Push code to code cloud (optional, extra points)

##2. Experimental process and results
1. Define a Searching and Sorting class, implement linearsearch and selectionSort methods in the class, and finally complete the test

  Code cloud link: https://e.gitee.com/besti-cs/repos/besti-cs/ljc20202306_Java/blob/bin/src/Sorting.java

      https://e.gitee.com/besti-cs/repos/besti-cs/ljc20202306_Java/blob/bin/src/Searching.java

2. Refactor your code

 

 

 

 

 

3. & 4. Reference http://www.cnblogs.com/maybe2030/p/4715035.html , learn various search algorithms, Supplement Search Algorithms in Searching and test them; Implement sorting methods (at least 3) and test the implemented algorithms (normal, abnormal and boundary)

 

  public class Fibonacci {
public boolean order(int[] arr,int target){
int i=0;
int a = target;
while(arr[i]!=target)
{
i++;
if(i==arr.length)
break;
}
return i==arr.length?false:true;
}
public void sort(int arr[]){
for(int i =1;i<arr.length;i++) {
for(int j=0;j<arr.length-i;j++) {
if(arr[j]>arr[j+1]) {
int temp = arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
public boolean binary(int[] arr,int min,int max,int mid,int target){
boolean found = false;
mid = (min + max) / 2;
int midd = mid;
if(arr[midd]==target)
found = true;
else if (arr[midd]!=target)
{
if(target<arr[midd])
{
max = midd-1;
midd--;
found = binary(arr,min,max,midd,target);
}
else if(target>arr[midd])
{
min = midd+1;
midd++;
found = binary(arr,min,max,midd,target);
}
}
return found;
}
public int binaryshow(int[] arr,int min,int max,int mid,int target){
int found = 0;
mid = (min + max) / 2;
int midd = mid;
if(arr[midd]==target)
found = arr[midd];
else if (arr[midd]!=target)
{
if(target<arr[midd])
{
max = midd-1;
midd--;
found = binaryshow(arr,min,max,midd,target);
}
else if(target>arr[midd])
{
min = midd+1;
midd++;
found = binaryshow(arr,min,max,midd,target);
}
}
return found;
}
public int[] hash(int[] arr){
int[] arr1 = {0,0,0,0,0,0,0,0,0,0,0,0};
for(int i=0;i<arr.length;i++)
{
if(arr1[arr[i]%11] == 0)
arr1[arr[i]%11] = arr[i];
else
{
for(int j=2;j<arr.length;j++)
if(arr1[j-1] == 0)
{
arr1[j-1] = arr[i];
break;
}
}
}
return arr1;
}
public int hashsearch(int[] result,int target){
int k = target%11,i,re = 0;
if(result[k]==target)
re = result[k];
else
{
for(i=k;k<result.length;k++)
{
if(result[k]==target)
{
re = result[k];
break;
}
}
}
return re;
}
public Linked[] linkedhash(Linked[] linked){
Linked[] arr1 = new Linked[12];
int i;
for(i=0;i<12;i++)
arr1[i] = new Linked(0);
for(i=0;i<linked.length;i++)
{
if((arr1[linked[i].getnum()%11]).getnum() ==

Posted by Sobbs on Thu, 11 Nov 2021 22:10:11 -0800