One search function

Assignment Help JAVA Programming
Reference no: EM13163518

You will create two Boolean array search functions. These functions will do a linear search of the array to see if the passed in integer value is present anywhere in an array of integers. This array is also passed to these search functions. A linear search means that your loop starts with the first entry in the array (at index position 0) and continues to the next array position until it reaches the end of the array or until a match is found.

One search function will use a sentinel to mark the end of the array. The other search function will use an array length (maximum legal index into the array) to determine when to exit the search loop. Both functions must return true when the search is successful and false when the value was not found.

The search-until-sentinel function searches the array for the value or until it sees the sentinel marker. This function has one int parameter that contains the value to be searched for (ValueToFind) and one int array containing the array of integers to be searched (DataArray). This DataArray is an array of integers with the sentinel at the end. The sentinel value is a -1 in the last position of the integer array.

The other search-until-last-index function searches the array for a specific number of positions. It has an int parameter (ValueToFind), another int parameter (LastValidIndex), and the array of integers (DataArray). This array of integers does not have a sentinel at the end. Instead, the loop searches until either ValueToFind is found or until we have searched the last position in the array as defined by LastValidIndex. LastValidIndex is the index in the array of the last entry in the array.

My work so far is:

#include "stdafx.h"

#include <iostream>

#include <iomanip>

using namespace std;

bool LinearSearch (int myarray[], int size, int lookfor ) // # looking for, size of the array, array looking in

{

int index;

for (index=0, index < size; index++;)

{

if (myarray[index] = lookfor)

{

printf("%d Number is present ");

return true;

}

}

return false;

}

bool SearchTillSentinel (int ValueToFind, int DataArrayWithSentinel[])

{

int index;

while (DataArrayWithSentinel[index] != -1)

{

if (DataArrayWithSentinel[index] = ValueToFind)

{

printf("%d Number is present ");

return true;

}

index++;

}

}

int _tmain(int argc, _TCHAR* argv[])

{

int SearchTillSentinel[] = {1,2,3,4,5,6,7,8,9,-1};

int LinearSearch[] = {11,12,13,14,15,16,17,18,19,20};

system ( "Pause" ) ;

return 0;

}

Reference no: EM13163518

Questions Cloud

State how do you find the mass of an unknown acid : How do you find the mass of an unknown acid in a 10mL portion used for titration if my original mass of the unknown acid is 0.307g
What is ka : What is Ka? The answer is 8.1E-10. Hope you can help
Advise tim and tom of their tax consequences : Tom had chosen to go to the exhibition because her family is in Indonesia and he took the opportunity to visit them while she was there. The conference ran for three days and she stayed on for an additional five days at her parents' home.
Define what mass of sucrose should be combined : What mass of sucrose should be combined with 514 g of water to make a solution with an osmotic pressure of 8.85 atm at 295 K? (Assume the density of the solution to be equal to the density of the solvent.)
One search function : One search function will use a sentinel to mark the end of the array. The other search function will use an array length (maximum legal index into the array) to determine when to exit the search loop. Both functions must return true when the searc..
What is the significance of the subjective data : What is the significance of the subjective and objective data provided with regard to follow-up diagnostic/laboratory testing, education, and future preventative care? Provide rationale for your answer.
Find calories and joules lost : find calories and joules lost when 75.0 g of water H20 cools from 86.4 degrees celsius to 2.1 degrees celsius.
Uses a 2-d array to store the highest and lowest temperature : Write a program that uses a 2-D array to store the highest and lowest temperatures for each montjh of the year. The program should output the average high, average low, and highest and lowest temperatures of the year. Your program must consist of ..
. write down each interaction with smartphone : Consider your smartphone as a system and use its calendar to set a calendar event with a reminder for your birthday. Write down each interaction between you and your smartphone as a scenario. Record all the interactions, including any feedback the sm..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create a driver class in java

Your project is to create a driver class that uses SuperJavaIceCreamClass.

  Write a recursive public method

Write a recursive public method in our BST class that returns a reference to the information in the node containing the smallest value in the tree. The signature of the method is

  The game of pig

Write a program that allows a single player to practice the game (that is, there will be no opponent, just a single player). Play 5 turns in the game to get a total score for the player. Refer to the sample output below for a detailed example.

  Write a java applet for grade of gas in costco gas station

Write a java applet (not a java application program) for costco gas station. The applet will first ask you whether you are a costco customer, then the grade of gas you want to use.

  Develop a reliable transfer protocol over udp

Develop a reliable transfer protocol over UDP. Focus on a Stop- and-Wait protocol.

  Write java program prints strings given at command line

Write down the program Average.java which just prints strings which it is given at command line, one per line. If nothing is given at command line, print "No arguments".

  Socket programming in java: tcp

In this project we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous service requests in parallel.

  Compilation and Execution - JAVA problem

Style marks are based on how your submitted code looks. Remember that good code is easily readable (and understandable) by someone who did not write it. For assignments, you should also include your name, student number, what course this is, what ass..

  Write java application to show successive element of array

Write down java application named GoTooFar which declares the array of 5 integers and stored five values in array. write try block in which you loop to show each successive element of array.

  Methods

Assignment describe the basic working of methods. How to write a method in java and how to call a method.

  Write a method called negative sum

Write a method called negativeSum that accepts a Scanner reading input from a file containing a series of integers, and print a message to the console indicating whether the sum starting from the first number is ever negative

  Create three classes for a customer

a travel manager and have a job of buying a travel package for a customer. You must create three classes for this programming challenge: Customer, Ticket, and TravelManagerDemo.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd