Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
306
306Ass4
Commits
35c71586
Commit
35c71586
authored
Feb 25, 2019
by
michael lundquist
Browse files
Adding a first attempt at all the methods required in this homework.
parent
1e4d219a
Pipeline
#3984
failed with stage
in 1 minute and 20 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
fourthassignment/src/main/java/com/ds/fourthassignment/CircularLinkedList.java
View file @
35c71586
...
...
@@ -42,11 +42,28 @@ public class CircularLinkedList {
size
++;
}
/**
* middle is neither at the beginning nor at the end
*
* @param newNode the node to be added to the middle of the list
*/
public
void
addToMiddle
(
LNode
newNode
)
{
int
curPos
=
0
;
LNode
curNode
=
head
;
if
(
this
.
size
>
2
){
while
(
curPos
<
this
.
size
/
2
){
curPos
++;
curNode
=
curNode
.
getNext
();
}
}
newNode
.
setNext
(
curNode
.
getNext
());
curNode
.
setNext
(
newNode
);
}
public
String
display
(){
String
out
=
""
;
if
(
head
==
null
)
return
null
;
LNode
current
=
head
;
LNode
current
=
head
;
do
{
out
+=
current
.
getData
()
+
","
;
if
(
current
==
tail
)
break
;
...
...
fourthassignment/src/main/java/com/ds/fourthassignment/DoublyLNode.java
View file @
35c71586
package
com.ds.fourthassignment
;
/**
* This now supports the scientist type
*/
public
class
DoublyLNode
{
private
S
tring
data
;
private
S
cientist
data
;
private
DoublyLNode
next
;
private
DoublyLNode
previous
;
public
DoublyLNode
(
S
tring
data
,
DoublyLNode
previous
,
DoublyLNode
next
){
public
DoublyLNode
(
S
cientist
data
,
DoublyLNode
previous
,
DoublyLNode
next
){
this
.
data
=
data
;
this
.
next
=
next
;
this
.
previous
=
previous
;
...
...
@@ -24,7 +28,7 @@ public class DoublyLNode {
public
boolean
hasPrevious
()
{
return
(
previous
==
null
?
false
:
true
);
}
public
S
tring
getData
()
{
return
data
;}
public
S
cientist
getData
()
{
return
data
;}
public
DoublyLNode
getNext
()
{
return
next
;
}
public
DoublyLNode
getPrevious
()
{
return
previous
;
}
...
...
fourthassignment/src/main/java/com/ds/fourthassignment/DoublyLinkedList.java
View file @
35c71586
...
...
@@ -82,4 +82,26 @@ public class DoublyLinkedList {
return
out
;
}
/**
* TODO
* Implement the method indexOfElement(Scientist s) to return the
* index of an input element (based on the name of a scientist). Suppose
* the elements are unique. Add this method to class DoubleLinkedList
*
* @return the index of this scientist, or -1
*/
public
int
indexOfElement
(
Scientist
s
){
DoublyLNode
curNode
=
head
;
int
curIndex
=
0
;
do
{
if
(
curNode
.
getData
().
compareTo
(
s
)
==
0
){
return
curIndex
;
}
curNode
=
curNode
.
getNext
();
curIndex
++;
}
while
(
curNode
.
hasNext
());
return
-
1
;
}
}
\ No newline at end of file
fourthassignment/src/main/java/com/ds/fourthassignment/TLinkedList.java
View file @
35c71586
...
...
@@ -39,7 +39,12 @@ public class TLinkedList {
}
/**
* TODO: check if addSorted works for:
*
* Create an add method that keeps nodes sorted in
descending order.
*/
/**
*This method adds nodes to the list and keeps the list sorted.
...
...
@@ -85,7 +90,6 @@ public class TLinkedList {
}
previous
.
setNext
(
node
);
size
++;
}
/**
...
...
@@ -122,4 +126,16 @@ public class TLinkedList {
*/
public
int
getSize
(){
return
size
;
}
/**
* Search method to perform linear search based on the
* name field of a scientist object. If the query is found, remove and
* return the matched Scientist object
*
* @param needle The scientist your searching for
* @return The found Scientist or null if no scientist was found
*/
public
Scientist
search
(
Scientist
needle
){
return
null
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment