-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheaterTicket.java
More file actions
89 lines (79 loc) · 1.57 KB
/
Copy pathTheaterTicket.java
File metadata and controls
89 lines (79 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* CS 162J
* Lab 1: TheaterTicket.java
* Author: Te-Feng (Dylan) Pan
* Last Modified: 04/17/2013
* -------------------------------
* This program prompts a filename and student IDs from user input
* and verifies ID#s from unsorted valid IDs that are loaded from the file, sn.txt.
* The testing program is TheaterTicketTester.java
*/
public class TheaterTicket
{
private String filename;
/**
* No-arg constructor
*/
public TheaterTicket()
{
filename = "";
}
/**
* This constructor accepts a String argument
* assigned to the filename
*/
public TheaterTicket(String f)
{
filename = f;
}
public static void sort(int[] arr)
{
for (int start = 0; start < arr.length; start++)
{
int lowest = arr[start];
int lowestIndex = start;
// inf lowest value in remaining array
for (int i = start+1; i < arr.length; i++)
{
if (arr[i] < lowest)
{
lowest = arr[i];
lowestIndex = i;
}
}
// need this temp varible to store and make swaping with start position
int temp = arr[start];
arr[start] = arr[lowestIndex];
arr[lowestIndex] = temp;
}
}
public static boolean binaryFind(int[] arr, int value)
{
int low = 0;
int high= arr.length-1;
while (high >= low)
{
// need to find the middle first
int middle = (high + low) / 2;
if (arr[middle] == value)
{
return true;
}
if (arr[middle] < value)
{
low = middle + 1;
}
if (arr[middle] > value)
{
high = middle - 1;
}
}
return false;
}
/*
public static int[] getArry()
{
int[] ;
return array;
}*/
}