Implement the addSecond method in IntSinglyLinkedList. This method takes an Integer as an argument and adds it as the second element in the list.
Here is an example of adding the Integer 7 to a list with two elements.
Abstract view: addSecond(7) on the list [12, 100] turns the list into [12, 7, 100]
Implement the rotateLeft method in IntSinglyLinkedList. It moves all elements closer to the front of the list by one space, moving the front element to be the last.
For example, here is what it looks like to rotateLeft once.
Abstract view: rotateLeft() on the list [12, 7, 100] turns the list into [7, 100, 12]
IntSinglyLinkedListTest.java
package net.datastructures;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.*;
public class IntSinglyLinkedListTest {
@Test
public void addSecondTest1() {
IntSinglyLinkedList s = new IntSinglyLinkedList();
s.addFirst(12);
s.addSecond(7);
// System.out.println(s);
assertEquals(2, s.size());
assertEquals(7, (int)s.last());
assertEquals(12, (int)s.first());
}
@Test
public void addSecondTest2() {
IntSinglyLinkedList s = new IntSinglyLinkedList();
s.addFirst(12);
s.addFirst(7);
s.addSecond(6);
assertEquals(3, s.size());
assertEquals(12, (int)s.last());
assertEquals(7, (int)s.first());
}
@Test
public void addSecondTest3() {
IntSinglyLinkedList s = new IntSinglyLinkedList();
s.addFirst(12);
s.addSecond(7);
s.addSecond(6);
s.addSecond(1);
assertEquals(4, s.size());
assertEquals(7, (int)s.last());
assertEquals(12, (int)s.first());
assertEquals(12, (int)s.removeFirst());
assertEquals(1, (int)s.first());
assertEquals(1, (int)s.removeFirst());
assertEquals(6, (int)s.first());
}
@Test
public void rotateLeft1() {
IntSinglyLinkedList s = new IntSinglyLinkedList();
s.addFirst(7);
s.addFirst(6);
s.addFirst(5);
s.addFirst(4);
s.addFirst(3);
s.rotateLeft();
assertEquals(4, (int)s.first());
assertEquals(3, (int)s.last());
s.rotateLeft();
assertEquals(5, (int)s.first());
assertEquals(4, (int)s.last());
s.rotateLeft();
assertEquals(6, (int)s.first());
assertEquals(5, (int)s.last());
s.rotateLeft();
assertEquals(7, (int)s.first());
assertEquals(6, (int)s.last());
s.rotateLeft();
assertEquals(3, (int)s.first());
assertEquals(7, (int)s.last());
}
}
IntSinglyLinkedList.java
/*
* Copyright 2014, Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
*
* Developed for use with the book:
*
* Data Structures and Algorithms in Java, Sixth Edition
* Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser
* John Wiley & Sons, 2014
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.datastructures;
/**
* A basic singly linked list implementation.
*
* @author Michael T. Goodrich
* @author Roberto Tamassia
* @author Michael H. Goldwasser
*/
/* CS2230
This version of IntSinglyLinkedList replaces the generic type Integer
with Integer. It may be easier to read if generic types
are hurting your brain.
*/
public class IntSinglyLinkedList {
//---------------- nested Node class ----------------
/**
* Node of a singly linked list, which stores a reference to its
* element and to the subsequent node in the list (or null if this
* is the last node).
*/
private static class Node {
/** The element stored at this node */
private Integer element; // reference to the element stored at this node
/** A reference to the subsequent node in the list */
private Node next; // reference to the subsequent node in the list
/**
* Creates a node with the given element and next node.
*
* @param e the element to be stored
* @param n reference to a node that should follow the new node
*/
public Node(Integer e, Node n) {
element = e;
next = n;
}
// Accessor methods
/**
* Returns the element stored at the node.
* @return the element stored at the node
*/
public Integer getElement() { return element; }
/**
* Returns the node that follows this one (or null if no such node).
* @return the following node
*/
public Node getNext() { return next; }
// Modifier methods
/**
* Sets the node's next reference to point to Node n.
* @param n the node that should follow this one
*/
public void setNext(Node n) { next = n; }
} //----------- end of nested Node class -----------
// instance variables of the IntSinglyLinkedList
/** The head node of the list */
private Node head = null; // head node of the list (or null if empty)
/** The last node of the list */
private Node tail = null; // last node of the list (or null if empty)
/** Number of nodes in the list */
private int size = 0; // number of nodes in the list
/** Constructs an initially empty list. */
public IntSinglyLinkedList() { } // constructs an initially empty list
// access methods
/**
* Returns the number of elements in the linked list.
* @return number of elements in the linked list
*/
public int size() { return size; }
/**
* Tests whether the linked list is empty.
* @return true if the linked list is empty, false otherwise
*/
public boolean isEmpty() { return size == 0; }
/**
* Returns (but does not remove) the first element of the list
* @return element at the front of the list (or null if empty)
*/
public Integer first() { // returns (but does not remove) the first element
if (isEmpty()) return null;
return head.getElement();
}
/**
* Returns (but does not remove) the last element of the list.
* @return element at the end of the list (or null if empty)
*/
public Integer last() { // returns (but does not remove) the last element
if (isEmpty()) return null;
return tail.getElement();
}
// update methods
/**
* Adds an element to the front of the list.
* @param e the new element to add
*/
public void addFirst(Integer e) { // adds element e to the front of the list
head = new Node(e, head); // create and link a new node
if (size == 0)
tail = head; // special case: new node becomes tail also
size++;
}
/**
* Adds an element to the end of the list.
* @param e the new element to add
*/
public void addLast(Integer e) { // adds element e to the end of the list
Node newest = new Node(e, null); // node will eventually be the tail
if (isEmpty())
head = newest; // special case: previously empty list
else
tail.setNext(newest); // new node after existing tail
tail = newest; // new node becomes the tail
size++;
}
/**
* Removes and returns the first element of the list.
* @return the removed element (or null if empty)
*/
public Integer removeFirst() { // removes and returns the first element
if (isEmpty()) return null; // nothing to remove
Integer answer = head.getElement();
head = head.getNext(); // will become null if list had only one node
size--;
if (size == 0)
tail = null; // special case as list is now empty
return answer;
}
@SuppressWarnings({"unchecked"})
public boolean equals(Object o) {
if (o == null) return false;
if (getClass() != o.getClass()) return false;
IntSinglyLinkedList other = (IntSinglyLinkedList) o; // use nonparameterized type
if (size != other.size) return false;
Node walkA = head; // traverse the primary list
Node walkB = other.head; // traverse the secondary list
while (walkA != null) {
if (!walkA.getElement().equals(walkB.getElement())) return false; //mismatch
walkA = walkA.getNext();
walkB = walkB.getNext();
}
return true; // if we reach this, everything matched successfully
}
public void rotateLeft() {
}
public void addSecond(Integer e) {
}
/**
* Produces a string representation of the contents of the list.
* This exists for debugging purposes only.
*/
public String toString() {
StringBuilder sb = new StringBuilder("(");
Node walk = head;
while (walk != null) {
sb.append(walk.getElement());
if (walk != tail)
sb.append(", ");
walk = walk.getNext();
}
sb.append(")");
return sb.toString();
}
public static void main(String[] args) {
IntSinglyLinkedList sl = new IntSinglyLinkedList();
sl.addLast(100);
sl.addLast(200);
sl.addLast(300);
System.out.println(sl.toString());
System.out.println("Removed " + sl.removeFirst());
System.out.println(sl.toString());
}
}
In: Computer Science
Practice Exercise 24: Determining the Appropriate Analysis
For each of the following scenarios, identify the appropriate
analysis. 1. The question is whether verbal reinforcement affects
response rates. Subjects in Group 1 were verbally reinforced every
time they respond to the instructor’s questions. Subjects in Group
2 were not. After 2 weeks, the two groups were compared by gauging
the number of students who raised their hand when questions were
asked. The following data were collected.
Group 1: 13, 15, 12, 17, 14, 14, Group 2: 10, 12, 12, 11, 13,
9
2. A guidance counselor at a high school wants to be best informed
about the universities and colleges that students prefer most
frequently. He glances at the institutions attended by last year’s
graduates and notes that the three closet colleges appear to have
about equal appeal. To test this assumption, he begins asking
students who are planning on postsecondary schooling where they
will apply. His data are as follows:
The technical institute: 22 The community college: 18 The
comprehensive university: 12
3. A biology instructor wishes to know if there is a difference
between performance on a state developed benchmark test and her
comprehensive final examination. To maintain consistency, both test
included the same number of questions (100), and the instructor
used the number of items correct as the grade. The following data
were collected from a sample of 10 students.
Student State exam Biology final
Student State exam Biology final
1 2 3 4 5
56 73 61 85 43
63 74 73 81 57
6 7 8 9 10
60 45 86 79 92
65 51 84 86 94
4. Assume that an educator wants to know how closely time spent
doing homework is related to student grades. Data was collected
from 8 students. Time spent on homework is reported in the number
of hours completed per night, and grades are reported on a 4-point
scale. The following data were collected.
| Student | Homework | Grades | Student | Homework | Grades |
| 1 | .25 | 2.00 | 5 | 1.00 | 2.00 |
| 2 | .50 | 1.75 | 6 | 1.25 | 2.25 |
| 3 | .75 | 2.00 | 7 | 1.50 | 2.00 |
| 4 | 1.00 | 2.50 | 8 | 2.00 | 3.69 |
5. Three groups of students involved in the same curriculum are
obliged to study for 15 minutes, 30 minutes, or 90 minutes a night
for 8 weeks before taking a mathematics test. Scores from 5
students in each group were randomly selected to determine if there
was a difference among the three time groups. Their scores are as
follows:
15 minutes: 43, 39, 55, 56, 73
30 minutes: 55, 58, 66, 79, 82
90 minutes: 61, 66, 85, 86, 91
6. An administrator is interested in determining if the type of
reading curriculum students receive is related to whether they meet
reading standards for their grade. The following data were
collected.
| Met Standard | 8 | 5 | 3 |
| Did Not Meet | 7 | 13 | 13 |
| Standard |
In: Statistics and Probability
During a blood-donor program conducted during finals week for college students, a blood-pressure reading is taken first, revealing that out of 200 donors, 28 have hypertension. All answers to three places after the decimal. A 95% confidence interval for the true proportion of college students with hypertension during finals week is (WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. , WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. ). We can be 80% confident that the true proportion of college students with hypertension during finals week is WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. with a margin of error of WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. . Unless our sample is among the most unusual 10% of samples, the true proportion of college students with hypertension during finals week Is between WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. and WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. . The probability, at 60% confidence, that a given college donor will have hypertension during finals week is WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. , with a margin of error of WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. . Assuming our sample of donors is among the most typical half of such samples, the true proportion of college students with hypertension during finals week is between WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. and WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. . We are 99% confident that the true proportion of college students with hypertension during finals week is WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. , with a margin of error of WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. . Assuming our sample of donors is among the most typical 99.9% of such samples, the true proportion of college students with hypertension during finals week is between WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. and WebAssign will check your answer for the correct number of significant figures. Incorrect: Your answer is incorrect. . Covering the worst-case scenario, how many donors must we examine in order to be 95% confident that we have the margin of error as small as 0.01? Incorrect: Your answer is incorrect. Using a prior estimate of 15% of college-age students having hypertension, how many donors must we examine in order to be 99% confident that we have the margin of error as small as 0.01? Incorrect: Your answer is incorrect.
In: Statistics and Probability
Book- Systems Analysis and Design in a Changing World 7th Edition
Data Integration at Cooper State UniversityCooper State University (CSU) has used a paper-and-pen-cil survey system to gather student feedback on instruc-tors and courses for over two decades. Paper forms are passed out to students during a class period near the end of the semester. Class information and survey questions are preprinted on the forms and empty circles are provided for each answer. Students fill in one of the circles for each question with a pencil. Written comments can be provided on the back of the form. The forms are delivered to a pro-cessing service in Nebraska, which scans the forms, sum-marizes the responses, and produces printed reports that are sent back to CSU along with the survey forms. The re-ports and survey forms are distributed to department chairs who review them and then distribute them to instructors.CSU wants to replace the existing system with a mod-ern online survey system. Several vendors market such systems as SaaS Web-based applications. The systems all have similar data integration needs with existing CSU systems, including the following:
■ Data about course sections, assigned instructor(s), and registered students must be imported from either CSU’s online learning management system (LMS) or its student information system (SIS)—the same sys-tem that stores grades and transcripts.
■ A survey for a specific student and course section must be accessible as a hyperlink from within the course section’s Web page in CSU’s online LMS. Instructors may configure the LMS to record whether a student has completed the survey in the grade book and provide points toward the course grade as a reward for completing the survey.
■ Access to the survey system should be restricted to CSU instructors, staff, administrators, and students using the same user ID and password they use to access other CSU applications. CSU uses a Central Authentication Server (CAS) to store usernames and passwords. Other CSU systems interact with a CAS Web service when they need to authenticate a user trying to access the system.
■ Students view their final course grades via a Web application that is part of the SIS. CSU wants to delay students’ ability to view their final grades by one week unless that student has completed surveys for all courses in which they are registered.Complete the following tasks:
1. Draw a network diagram that summarizes the sys-tems described above; devices used by administra-tors, staff, instructors, and students; and the network connections among them. Assume that the current survey system will be replaced by a new Web-based system. Assume further that each existing CSU sys-tem is hosted on its own server.
2. Which systems need access to current data regarding course sections, their assigned instructors, and regis-tered students? Select a system to be the system of record for that data and justify your decision. Draw a diagram similar to Figure 7-21 to summarize all required synchronizations
In: Computer Science
***pls note i am re asking some questions as the answers i was provided for the 80 questions i asked only 39 were correct.**
Carefully read the " Interpretation" section of the instructions
before answering questions
does the proposed Conclusion follows or Conclusion does not follow
the information.
Information: In a certain city where school attendance laws are
strictly enforced, it was found that only 15 percent of the
students had a perfect attendance
record during a single school semester. Among those who sold
newspapers, however, 25 percent had a perfect attendance record
during the same semester.
Proposed conclusion: Students who sold newspapers were more likely to have perfect attendance records during the semester than students who did not.
Information: In a certain city where school attendance laws are
strictly enforced, it was found that only 15 percent of the
students had a perfect
attendance record during a single school semester. Among those who
sold newspapers, however, 25 percent had a perfect attendance
record during the same semester.
Proposed conclusion: Strict enforcement of school attendance laws in this city did not prevent 85 percent of the students from being absent sometime during the semester.
Information: In a certain city where school attendance laws are strictly enforced, it was found that only 15 percent of the students had a perfect attendance record during a single school semester. Among those who sold newspapers, however, 25 percent had a perfect attendance record during the same semester.
Proposed conclusion: If truants were given jobs selling newspapers, their school attendance would improve.
Information: In a certain city where school attendance laws are strictly enforced, it was found that only 15 percent of the students had a perfect attendance record during a single school semester. Among those who sold newspapers, however, 25 percent had a perfect attendance record during the same semester.
Proposed conclusion: The low rate of perfect attendance by students in that school system was due mainly to illness or injury.
Information: When I go to bed at night, I usually fall asleep quite
promptly. But about twice a month I drink coffee during the
evening, and whenever I do, I lie awake and toss for
hours.
Proposed conclusion: My problem is mostly psychological: I expect that the coffee will keep me awake and therefore it does.
Information: When I go to bed at night, I usually fall asleep quite
promptly. But about twice a month I drink coffee during the
evening, and whenever I do, I lie awake and toss for
hours.
Proposed conclusion: I don't fall asleep promptly at night after drinking coffee because the caffeine in it overstimulates my nervous system.
Information: When I go to bed at night, I usually fall asleep quite
promptly. But about twice a month I drink coffee during the
evening, and whenever I do, I lie awake and toss for
hours.
Proposed conclusion: On nights when I want to fall asleep promptly, I'd better not drink coffee in the evening.
In: Psychology
eCampusOntario.ca is the primary face of the Ontario Online Learning Consortium (OOLC), a not-for-profit corporation whose membership is composed of all publicly-funded colleges and universities in Ontario. Funding for OOLC and the eCampusOntario initiative comes from the Government of Ontario. eCampusOntario.ca was created in 2015 primarily as a portal for learners to find online courses – through browsing, searching by keyword, or filtering by institution and delivery format. Course details include links to information about scheduling, tuition and fees, instructors, and information about how to get registered and to seek credit transfer. Previously identified course equivalencies are also listed where available. In addition, students can search based on a specific course they need credit for to find available online options at other institutions. Aiming to improve its services, eCampusOntario has selected a sample of 33 nursing, 33 business and 33 education students who intend to use eCampusOntario website to search and register for e-courses. The sampled students were asked to indicate their overall satisfaction of eCampusOntario portal prior to registration for any courses (stage 1) and after registration (stage 2). The following information is available for each respondent: - Age of the respondents - Gender (1=male and 2=female) - Student satisfaction of stage 1 (a continuous number that ranges from 0 (extremely dissatisfied) to 5 (extremely satisfied)) - Student satisfaction of stage 2 (a continuous number that ranges from 0 (extremely dissatisfied) to 5 (extremely satisfied)) * Assume the collected data is normally-distributed.
Assignment Questions: 1. Conduct a descriptive analysis of the sample of business stream students by choosing two variables and focusing on measures of central location and variance. Represent these variables using two appropriate graphs for each. In addition, represent the relationship between age and student satisfaction for each stage using an appropriate graph. (15%)
2. Some eCampusOntario employees believe more information is provided to business students during stage 1 (pre registration) as opposed to stage 2 (post registration). Is there evidence to suggest there are significant differences between the business student’s satisfactions of the two stages. (30%)
3. Estimate the difference between business student satisfaction during stage 1 and 2 with 95% confidence. Interpret the results. (20%)
4. eCampusOntario would also like to know if differences exist between the satisfaction level of nursing students, business students and education students during stage 2. Assume the variables have equal variance. (30%) Assume alpha = 0.05 wherever necessary. Hint: Pay attention to the experimental design; are the samples independent or paired?
Answer each question using Excel. Do each question on a separate Excel Sheet.
Answer each question using Excel. Do each question on a separate Excel Sheet. - For #2 – 4 do the following: • State your chosen method of analysis and justify its use. Were the required conditions met? If the question involves testing a hypothesis, state the hypotheses. Include the Excel results in readable format. • Discuss the findings of the study by answering the following questions: ➢ What are they? ➢ What do they mean? ➢ How can they help in decision making?
In: Advanced Math
7.
During the development of a frog's fertilized egg, the following takes place:
| A. |
Rapidly dividing cells lead to the formation of the "animal pole" in a region of the egg that is rich in amino acids and nucleic acids precursors. |
|
| B. |
Cells divide more slowly in the "vegetal pole" as they are located in a region of the egg richer in lipids with fewer amino acids and nucleic acid precursors. |
|
| C. |
In early stages of development, cells are dividing so fast that the embryo does not increase in volume. |
|
| D. |
All of the above |
8.
Find the incorrect description.
| A. |
Light Microscopy — Usually has a resolution of 0.2 µm and a maximum magnification of 1000X. Light goes through the specimen. It usually requires staining of specimens (cells, tissue slices) |
|
| B. |
Confocal Microscopy — Allows visualization of cells in three dimensions because it takes images in optical sections and integrates them using computer power. |
|
| C. |
Atomic Force Microscopy — Similar in principle to light microscopy, but uses an electron beam instead of photons. Enlargement up to 106X and resolution of biological specimens about 1 nm. |
|
| D. |
Fluorescence Microscopy — Excitation light is absorbed by fluorescent probes in the specimen and reemitted at a lower energy, i.e., a longer wavelength. |
9.
During titration of glycine with HCl, what is the proportion of +H3N–CH2–COO– /+H3N–CH2–COOH at pKa1?
| A. |
75%/25% |
|
| B. |
0%/100% |
|
| C. |
50%/50% |
|
| D. |
25%/75% |
11.
Consider the compound pairs below:
What is their correct order, from the most oxidized to the most reduced?
| A. |
v > iii > i > iv > ii |
|
| B. |
i > iv > ii > v > iii |
|
| C. |
i > ii > iii > iv > v |
|
| D. |
v > iv > iii > ii > i |
In: Biology
1-D Kinematics
Experiment 1: Free Fall
In this experiment you will drop the hex nut from different heights. You will explore how height from which the hex nut is dropped affects its falling time and its final velocity.
|
Materials:
|
Procedure
Include your measurements in Table 1.
v = v0 + at
Since the initial velocity (the one you start with) in this experiment is always equal to 0 m/s, then the equation you use for calculation is simply:
v = at
Example:
If average t = 2.5 seconds then,
v = a (2.5 s)
Since an object is in free fall, acceleration a is equal to gravitational acceleration g = 9.8 m/s2.
Therefore,
v = (9.8 m/s2)(2.5 s) = 24.5 m/s
Data:
Table 1
|
Height (m) |
Time (s) |
Average Time (s) |
Final Velocity (m/s) |
Independent Variable: _____________
Dependent Variable: ________________
[include your graph here]
Independent Variable: _____________
Dependent Variable: ________________
[include your graph here]
In: Physics
BUCK FILTER TRANSFER FUNCTION (CCM) USING MATLAB
I. State-space Modelling and Transfer Function of Ideal Buck Converter
1. Write the AC state-space for an ideal Buck Converter under
CCM, given
the state-variables iL^(t) and vc^(t),
input variables d^(t) and vs^(t), and
output variables iL^(t) and vc^(t).
2. Create the state-space model in Matlab using R=5/3 ohms, L=10 uH, C=242 uF, Vs=Vin= 20 V, Vo = 5 V, D=5/20
3. Extract the transfer functions from the state-space
model.
vo^(s)/vs^(s),
vo^(s)/d^(s),
iL^(s)/vs^(s),
iL^(s)/d^(s)
4. Write the expressions for the transfer functions.
5. Plot the pole-zero maps, step-responses, and Bode plots of the transfer functions.
II. State-space Modelling and Transfer Function of Buck Converter with Parasitics
1. Write the AC state-space for an ideal Buck Converter under
CCM, given
the state-variables iL^(t) and vc^(t),
input variables d^(t) and vs^(t), and
output variables iL^(t) and vo^(t).
2. Create the state-space model in Matlab using R=5/3 ohms, L=10 uH, C=242 uF, Vs=Vin = 20 V, Vo = 5 V, D=5/20, rL=25mohm, rC=25mohm
3. Extract the transfer functions from the state-space
model.
vo^(s)/vs^(s),
vo^(s)/d^(s),
iL^(s)/vs^(s),
iL^(s)/d^(s)
4. Write the expressions for the transfer functions.
5. Plot the pole-zero maps, step-responses, and Bode plots of the transfer functions.
In: Electrical Engineering
Do a trace on the binarySearch method below: variable key holds the value 17, and
variable list is a reference to an array with these values {9, 20, 23, 28, 33, 38, 42, 48, 54, 61,73}.
public static int binarySearch(int[] list, int key) {
Each row in the table below corresponds to one iteration of the while loop in the method above. You can add or remove rows according to the actual number of iterations. The first row’s information corresponds to the first iteration, and its value has been filled. You need to continue for the following rows.
|
key |
lowIndex |
highIndex |
highIndex>=lowIndex |
midIndex |
key==list[midIndex] |
key<list[midIndex] |
|
17 |
0 |
10 |
true |
5 |
false |
true |
int lowIndex = 0;
int highIndex = list.length - 1;
while (highIndex >= lowIndex) {
int midIndex = (lowIndex + highIndex) / 2;
if (key < list[midIndex]){
highIndex = midIndex - 1;
}
else if (key > list[midIndex]){
lowIndex = midIndex + 1;
}
else if (key == list[midIndex]){
return midIndex;
}
} // end of while loop
return -1;
} // end of binary search method
In: Computer Science