Asked by Raymond
                Trying to create a program using following algorithms.
JumpSearch(list,lower,upper,jump,x)
{Look for X in List[lower ... upper].
Report its position if found, else report 0. List is sorted in increasing order.
upper>=lower>0; upper-lower+1>=jump>=1.}
index = lower + jump -1
while upper > index and x> list [index]
index = index + jump
if upper > index
upper = index
LinearSearch(list,index-jump+1, upper, x)
This is so far I have, I don't the program is not correct. Can anyone help me complete it or guide it so that I can complete it.
{
class Program
{
public int JumpSearch (int[] list, int lower, int upper, int jump, int X)
{
int index = lower + jump - 1;
while (upper > index && X > list[index])
{
index = index + jump;
}
if (upper > index)
{ upper = index; }
return -1;
}
static void Main(string[] args)
{
int Index;
int Item;
int lower = 0, upper = 9;
int[] list = new int[10] {1,2,3,4,5,6,7,8,9,10};
                                        
            
Console.WriteLine("\nEnter the number you want to search the position.\n");
Item = int.Parse(Console.ReadLine());
Program p = new Program();
Index = p.JumpSearch(list, lower, upper, Item,1);
if (Index == -1)
{
Console.WriteLine("The number you entered could not be found. Please enter different number from the list.");
}
else
{
Console.WriteLine("The number you entered is found at {0} position in the list.", Index);
}
Console.ReadLine();
}
}
}
            
        JumpSearch(list,lower,upper,jump,x)
{Look for X in List[lower ... upper].
Report its position if found, else report 0. List is sorted in increasing order.
upper>=lower>0; upper-lower+1>=jump>=1.}
index = lower + jump -1
while upper > index and x> list [index]
index = index + jump
if upper > index
upper = index
LinearSearch(list,index-jump+1, upper, x)
This is so far I have, I don't the program is not correct. Can anyone help me complete it or guide it so that I can complete it.
{
class Program
{
public int JumpSearch (int[] list, int lower, int upper, int jump, int X)
{
int index = lower + jump - 1;
while (upper > index && X > list[index])
{
index = index + jump;
}
if (upper > index)
{ upper = index; }
return -1;
}
static void Main(string[] args)
{
int Index;
int Item;
int lower = 0, upper = 9;
int[] list = new int[10] {1,2,3,4,5,6,7,8,9,10};
Console.WriteLine("\nEnter the number you want to search the position.\n");
Item = int.Parse(Console.ReadLine());
Program p = new Program();
Index = p.JumpSearch(list, lower, upper, Item,1);
if (Index == -1)
{
Console.WriteLine("The number you entered could not be found. Please enter different number from the list.");
}
else
{
Console.WriteLine("The number you entered is found at {0} position in the list.", Index);
}
Console.ReadLine();
}
}
}
Answers
                    Answered by
            alison
            
    i like this programming
    
                                                    There are no AI answers yet. The ability to request AI answers is coming soon!
                                            
                Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.