Hello:
I'm having trouble with figuring out how to write the corrected methods for boolean delete(string s) , boolean deleteRange(string s), displayNoLF(), display() and boolean merge(OrderedStringList a, OrderedStringList b )/>
this is what I have so far
/>/>
Is delete correct?
deleteRange, I'm stuck on if any of the values were deleted...
for the displayNoLF it should use print to show the strings in order without index numbers, and without newlines in between them
for the display it should use println to show the strings in order, with index numbers, space nicely in a vertical column (how do I do that?)
and for the merge is that correct?
here is what the assignment says:
This assignment will build a specialized array ADT similar to those illustrated in the
textbook. Build the ADT object according to the interface described below, and write a
main program to fully exercise each of the methods implemented. Use the textbook/inclass examples as a guide. DO NOT USE ANY WHILE (TRUE) CONSTRUCTS OR
BREAK STATEMENTS TO HALT ANY LOOP PREMATURELY!
and this is my main which I have not worked on yet, because I prefer to finish the methods first
I'm having trouble with figuring out how to write the corrected methods for boolean delete(string s) , boolean deleteRange(string s), displayNoLF(), display() and boolean merge(OrderedStringList a, OrderedStringList b )/>
this is what I have so far
package orderedstringlist;
public class OrderedStringList {
private String[] list;
private int used;
public OrderedStringList(int size) {
list = new String[size];
used = 0;
}
public int size() {
return used;
}
public int find(String s) {
int storage = -1;
for (int i = 0; i < size(); i++) {
String a = list[i];
if (s.equals(a)) {
storage = i;
}
}
return storage;
}
public boolean insert(String s) {
if (size() >= list.length) {
return false;
}
int storage = used;
// this loop finding index for place to put s
for (int i = 0; storage == used && i < size(); i++) {
String a = list[i];
if (s.compareTo(a) <= 0) {
storage = i;
}
}
// moves everything over to make room for s
for (int i = used - 1; i >= storage; i--) {
list[i + 1] = list[i];
}
//
list[storage] = s;
used++;
return true;
}
public boolean delete(String s) {
if (size() >= list.length) {
return false;
}
int storage = used;
for (int i = 0; storage == used && i < size(); i++) {
String a = list[i];
if (s.compareTo(a) >= 0) {
storage = i;
}
}
list[storage] = s;
used--;
return true;
}
public boolean deleteRange(String start, String stop) {
int starti = find(start);
int stopi = find(stop);
if (starti == -1 || stopi == -1 || starti < stopi) {
return false;
}
int numDel = stopi - starti; // plus one
for ( i =0, i < numDel, i--) {
}
}
public void displayNoLF() {
System.out.print(list);
}
public void display() {
System.out.println(list );
}
public boolean merge(OrderedStringList a, OrderedStringList B)/>/>/> {
OrderedStringList x = new OrderedStringList();
OrderedStringList y = new OrderedStringList();
OrderedStringList z = new OrderedStringList(2);
}
}
Is delete correct?
deleteRange, I'm stuck on if any of the values were deleted...
for the displayNoLF it should use print to show the strings in order without index numbers, and without newlines in between them
for the display it should use println to show the strings in order, with index numbers, space nicely in a vertical column (how do I do that?)
and for the merge is that correct?
here is what the assignment says:
This assignment will build a specialized array ADT similar to those illustrated in the
textbook. Build the ADT object according to the interface described below, and write a
main program to fully exercise each of the methods implemented. Use the textbook/inclass examples as a guide. DO NOT USE ANY WHILE (TRUE) CONSTRUCTS OR
BREAK STATEMENTS TO HALT ANY LOOP PREMATURELY!
and this is my main which I have not worked on yet, because I prefer to finish the methods first
package orderedstringlist;
public class Main {
public static void main(String[] args) {
OrderedStringList myList = new OrderedStringList(7);
System.out.println("Adding Apple, banana, cherry, duck, elephant, falcon, & giraffe");
myList.insert("Apple");
myList.insert("banana");
myList.insert("cherry");
myList.insert("duck");
myList.insert("elephant");
myList.insert("falcon");
myList.insert("giraffe");
myList.displayNoLF();
}
}