The document describes the methods available in the List and Iterator interfaces in Java. It provides examples of how to use each method, including adding, removing, and accessing elements in a list; iterating through a list using an iterator; and getting information about the iterator's current position. Some key methods covered are add, remove, contains, get, size, iterator, and next for the List interface and hasNext, next, remove for the Iterator interface.
Kotlin For Android - Collections APIs (part 6 of 7)Gesh Markov
This presentation is part of a workshop series.
In this section you will learn mapping, transforming, filtering, aggregating, and associating anything you can iterate over like a boss.
License:
This presentation is licensed under the Creative Commons, No Derivatives, Version 3.0 US: https://creativecommons.org/licenses/by-nd/3.0/us/legalcode
Kotlin For Android - Collections APIs (part 6 of 7)Gesh Markov
This presentation is part of a workshop series.
In this section you will learn mapping, transforming, filtering, aggregating, and associating anything you can iterate over like a boss.
License:
This presentation is licensed under the Creative Commons, No Derivatives, Version 3.0 US: https://creativecommons.org/licenses/by-nd/3.0/us/legalcode
Engineering lecture ppt by venay magenvenaymagen19
Venay Magen likes the shading red, particularly on Tuesdays. He cherishes to drink bourbon (on all days). He figured out how to drink whisky from his youth companion Zippo, when they went to class together at Mount Temple Comprehensive School. He is best known as the lead vocalist for the band MN3.
Stacks and Queues: Introduction to stacks
applications of stacks
implementation and comparison of stack implementations.
Introduction to queues
applications of queues and implementations
Priority Queues and applications
A stack is a basic data structure that can be logically thought as linear structure represented by a real physical stack or pile, a structure where insertion and deletion of items take place at one end called the top of the stack.
Engineering lecture ppt by venay magenvenaymagen19
Venay Magen likes the shading red, particularly on Tuesdays. He cherishes to drink bourbon (on all days). He figured out how to drink whisky from his youth companion Zippo, when they went to class together at Mount Temple Comprehensive School. He is best known as the lead vocalist for the band MN3.
Stacks and Queues: Introduction to stacks
applications of stacks
implementation and comparison of stack implementations.
Introduction to queues
applications of queues and implementations
Priority Queues and applications
A stack is a basic data structure that can be logically thought as linear structure represented by a real physical stack or pile, a structure where insertion and deletion of items take place at one end called the top of the stack.
Class DiagramIn the Assignment #10, you are given three files Ass.pdfxlynettalampleyxc
Class Diagram:
In the Assignment #10, you are given three files Assignment10.java, LinkedList.java, and
ListIterator.java. You will need to add additional methods in the LinkedList class in the
LinkedList.java file. The LinkedList will be tested using strings only.
Specifically, the following methods must be implemented in the LinkedList class:
(You should utilize listIterator() method already defined in the LinkedList class to obtain its
LinkedListIterator object, and use the methods in the LinkedListIterator class to traverse from
the first element to the last element of the linked list to define the following methods.)
1.
public String toString()
The toString method should concatenate strings in the linked list, and return a string of the
following format:
{ Apple Banana Melon Orange }
Thus it starts with \"{\" and ends with \"}\", and there is a space between strings and \"{\" or
\"}\". If the list is empty, it returns \"{ }\" with a space in between.
2.
public boolean isEmpty()
The isEmpty method returns true of the linked list is empty, false otherwise.
3.
public void addElement(Object element)
The addElement adds the parameter element at the parameter in the linked list in alphabetical
order. For instance, if the linked list contains {Apple, Banana, Grape}, and a user tries to add
\"Carrot\", then it should be added as:
{Apple, Banana, Carrot, Grape}.
4.
public Object removeElement(int index)
The removeElement removes the string (Object) at the parameter index and returns it. Note that
this index starts with 0 just like array indices. For instance, if the linked list contains {Apple,
Banana, Carrot, Grape} and the parameter index is 3, then \"Grape\" should be remove. If the
parameter index is larger or smaller than the existing indices, it should throw an object of the
IndexOutOfBoundsException class (and the content of the linked list should remain unchanged).
5.
public Object getElement(int index)
The getElement searches the string (Object) at the parameter index and returns it. Note that this
index starts with 0 just like array indices. For instance, if the linked list contains {Apple, Banana,
Carrot, Grape} and the parameter index is 3, then \"Grape\" will be returned. If the parameter
index is larger or smaller than the existing indices, it should throw an object of the
IndexOutOfBoundsException class (and the content of the linked list should remain unchanged).
6.
public void searchAndReplace(Object oldString, Object newString)
The searchAndReplace method searches all occurrences of the first parameter string (object) in
the list, and replaces them with the second parameter string (object). If the parameter string does
not exist in the linked list, then the linked list content will not change.
7.
public int indexOfLast(Object searchString)
The indexOfLast searches the parameter string (object) with the largest index, and returns its
index. If the parameter string does not exist in the linked list, then it should return -1.
For i.
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
/**
The LinkedList1 class implements a Linked list.
*/
class LinkedList1
{
/**
The Node class stores a list element
and a reference to the next node.
*/
private class Node
{
String value;
Node next;
/**
Constructor.
@param val The element to store in the node.
@param n The reference to the successor node.
*/
Node(String val, Node n)
{
value = val;
next = n;
}
/**
Constructor.
@param val The element to store in the node.
*/
Node(String val)
{
// Call the other (sister) constructor.
this(val, null);
}
}
private Node first; // list head
private Node last; // last element in list
/**
Constructor.
*/
public LinkedList1()
{
first = null;
last = null;
}
/**
The isEmpty method checks to see
if the list is empty.
@return true if list is empty,
false otherwise.
*/
public boolean isEmpty()
{
return first == null;
}
/**
The size method returns the length of the list.
@return The number of elements in the list.
*/
public int size()
{
int count = 0;
Node p = first;
while (p != null)
{
// There is an element at p
count ++;
p = p.next;
}
return count;
}
/**
The add method adds an element to
the end of the list.
@param e The value to add to the
end of the list.
*/
public void add(String e)
{
if (isEmpty())
{
first = new Node(e);
last = first;
}
else
{
// Add to end of existing list
last.next = new Node(e);
last = last.next;
}
}
/**
The add method adds an element at a position.
@param e The element to add to the list.
@param index The position at which to add
the element.
@exception IndexOutOfBoundsException When
index is out of bounds.
*/
public void add(int index, String e)
{
if (index < 0 || index > size())
{
String message = String.valueOf(index);
throw new IndexOutOfBoundsException(message);
}
// Index is at least 0
if (index == 0)
{
// New element goes at beginning
first = new Node(e, first);
if (last == null)
last = first;
return;
}
// Set a reference pred to point to the node that
// will be the predecessor of the new node
Node pred = first;
for (int k = 1; k <= index - 1; k++)
{
pred = pred.next;
}
// Splice in a node containing the new element
pred.next = new Node(e, pred.next);
// Is there a new last element ?
if (pred.next.next == null)
last = pred.next;
}
/**
The toString method computes the string
representation of the list.
@return The string form of the list.
*/
public String toString()
{
StringBuilder strBuilder = new StringBuilder();
// Use p to walk down the linked list
Node p = first;
while (p != null)
{
strBuilder.append(p.value + \"\ \");
p = p.next;
}
return strBuilder.toString();
}
/**
The remove method removes the element at an index.
@param index The index of the element to remove.
@return The element removed.
@exception IndexOutOfBoundsException When index is
out of bounds.
*/
public String remove(int index)
{
if (index < 0 || index >= size())
{
String message = String.valueOf(index);
throw new IndexOutOfBoundsException(message);
}
String element; // The element to return
if (index == 0)
{
// Removal of first item in the list
element.
For this lab you will complete the class MyArrayList by implementing.pdffashiongallery1
Find the time it takes the boat to travel the given distance. A ball is thrown vertically upward
with a speed of 40.0 m/s. How high does it rise? How long does it take to reach its highest
point? How long does the ball take to hit the ground after it reaches its highest point? What is
its velocity when it returns to the level from which it started? The center of mass moves with
constant acceleration when constant forces act on the object. A gym ground. How high above
this point is her center of mass at the following times? Ignore the effects
Solution
initial velocity, u = + 40 m/s
a = - 9.8 m/s^2
(a) it will rise until its velocity becomes zero.
hence final velocity, v = 0
Applying, v^2 - u^2 = 2 a h
0^2 - 40^2 = 2(-9.8)(h)
h = 81.63 m
(B) v = u + at
0 = 40 - 9.8 t
t = 4.08 sec
(C) now for motion from highest point to ground,
initial velocity, v (velocity at highets point) = 0
displacement, y = - 81.63 m
a = - 9.8 m/s^2
applying, y = u t + a t^2 /2
- 81.63 = 0 - 9.8 t^2 / 2
t = 4.08 s
(D) applying v = u + at
v = 0 + (-9.8)(4.08)
v = - 40 m/s
(minus sign indicates that direction is downwards).
Lecture 18Dynamic Data Structures and Generics (II).docxSHIVA101531
Lecture 18
Dynamic Data Structures and Generics (II)
*
*
Class ArrayListObject of an ArrayList can be used to store an unlimited number of objects.
*
Methods of ArrayList (I)
*
java.util.ArrayList
+ArrayList()
+add(o: Object) : void
+add(index: int, o: Object) : void
+clear(): void
+contains(o: Object): boolean
+get(index: int) : Object
+indexOf(o: Object) : int
+isEmpty(): boolean
+lastIndexOf(o: Object) : int
+remove(o: Object): boolean
+size(): int
+remove(index: int) : Object
+set(index: int, o: Object) : Object
Appends a new element o at the end of this list.
Adds a new element o at the specified index in this list.
Removes all the elements from this list.
Returns true if this list contains the element o.
Returns the element from this list at the specified index.
Returns the index of the first matching element in this list.
Returns true if this list contains no elements.
Returns the index of the last matching element in this list.
Removes the element o from this list.
Returns the number of elements in this list.
Removes the element at the specified index.
Sets the element at the specified index.
Creates an empty list.
Methods of ArrayList (II) Array is used to implement the methodsMethods get(int index) and set(int index, Object o) for accessing and modifying an element through an index and the add(Object o) for adding an element at the end of the list are efficient. Why?Methods add(int index, Object o) and remove(int index) are inefficient because it requires shifting potentially a large number of elements.
*
Linked Data StructureTo improve efficiency for adding and removing an element anywhere in a list.It containsCollection of objectsEach object contains data and a reference to another object in the collection
*
Linked ListA dynamic data structureA linked list consists of nodes. Each node contains an elementa link: linked to its next neighbor. Example: take notes in the class!
*
Linked List
*
ListNodes
ListNodes in Linked List
public class ListNode { // fill the comments
private String data; //
private ListNode link; //
/** */
public ListNode () {
link = null; //
data = null; //
}
/** */
public ListNode (String newData, ListNode linkValue) {
data = newData;
link = linkValue;
}
*
ListNodes in Linked List (cont’d)
/** */
public void setData (String newData) {
data = newData;
}
/** */
public String getData () {
return data;
...
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfrishabjain5053
Implement the interface you wrote for Lab B (EntryWayListInterface). As a reminder,
EntryWayListInterface allows the user to access to list elements only through the beginning and
end of the list.
Your implementation can use either an expandable array or linked nodes- it is your choice. You
can decide what instance variables are needed. You must implement every method from the
interface. Make sure to account for special conditions such as empty lists and singleton lists.
Note: your instance data variable should be either a) an array or b) one or more nodes. It should
not be an AList or LList object or an ArrayList object.
Your implementation must:
compile
contain these implemented methods:
insertHead
insertTail
deleteHead
deleteTail
display
contains
isEmpty
isFull
Also create a driver program to test your implementation. The driver program will operate from
the client perspective. Your driver program should:
display an empty list
add five entries to the list- some at the head and some at the tail
display the list
remove the first entry
remove the last entry
display the list
test to see if elements are in the list (test one element that is in the list and one that is not)
remove the last three elements in the list
try to remove an element from the empty list
Write a second class to implement EntryWayListInterface. Instead of using an array or linked
nodes, use either an AList or LList object as your instance data variable. In this way, you are
using an existing data type (AList or LList) to implement a new data type
(EntryWayListInterface). Inside the methods of this class, invoke methods on the AList or LList
object to accomplish the task.
/** An interface for the ADT list.
Entries in a list have positions that begin with 1.
* Accesses only entries that are the head or tail of the list.
*/
public interface EntryWayInterface {
/** Adds a new entry to this list T.
* @param newEntry The object to be added as a new entry.
* @return True if the addition is successful, or false if not. */
public boolean insertHead(T newEntry);
/** Deletes a new entry to this list T.
* @param newEntry The object to be added as a new entry.
* @return True if the addition is successful, or false if not. */
public boolean insertTail(T newEntry);
/** Deletes the object that is at the head of list T.
* @return the object that has been deleted and returns
* null if no object was deleted.
*/
public T deleteHead();
/** Deletes the object that is at the tail of list T.
* @return the object that has been deleted or else return null
* if no object was deleted.
*/
public T deleteTail();
/** Displays the contents of the list T.
*/
public void display();
/** See whether this list T contains a given entry.
* @param anEntry The object that is the desired entry.
* @return the position of the entry that was found.
* else returns false if the object is not in the list.
*/
public int contains(T anEntry);
/** Sees whether this list is empty.
* @return True if the list is empty, or false.
Implementation The starter code includes List.java. You should not c.pdfmaheshkumar12354
Implementation The starter code includes List.java. You should not change anything in List.java.
Your task will be to create LinkedList.java, make LinkedList use generics and inherit from List,
and complete several methods in LinkedList.java. Create LinkedList.java in IntelliJ. Add a main
method to LinkedList.java containing the following code. Your program will not compile again.
public static void main(String[] args) { LinkedList list = new LinkedList();
System.out.println(list.getHead()); System.out.println(list.getTail()); list.add("first");
list.add("middle"); list.add("last"); System.out.println(list.getHead().value);
System.out.println(list.getTail().value); System.out.println(list); } The first issue is that your
LinkedList class does not have a way of specifying what type of data it should store. You can fix
this using Java Generics. Change the first line of your class to the following: LinkedList .
Confirm that the first line in your main method no longer has an error. On the line that declares
the LinkedList class, add extends List before the bracket that begins the class. The first line in
your class will now have a compile error because LinkedList does not implement the methods
required by the List abstract class. Press Ctrl-i to have IntelliJ insert stubs of these methods.
Ensure that Copy JavaDoc is selected so you get JavaDoc comments which describe the method
requirements, then click OK. Your code should now compile again. Next add fields for the head
and tail. These will be of type Node. Create a getHead method which returns your head field, and
a getTail method which returns your tail field. Run your main method now and you will see that
there is a NullPointerException because the add method does not actually add anything to the
list, so head and tail will always be null. Complete the method boolean add(T value) for which
IntelliJ gave you a stub. You need to create a new node with value to add at the end of the list.
This means you will need to connect it to the old tail and update tail to point to the node you
created. Make sure that you handle the case where the list is empty and both head and tail should
be set to the new node you've created. Note: For the full Map I assignment, add will need to
prevent duplicate values being added to the list and should return true or false based on whether
the value was added or not. For this lab, you can ignore this requirement and simply return true.
Add a toString method to your LinkedList class. It should start at the head of your list and
proceed through all the nodes in a loop, combining the values of each node with a comma
between each and square brackets containing the whole thing. When you run your main method,
the final thing printed should be: [first, middle, last] List.java: /** * Specification for a List
ADT. * @author Shubham Chatterjee * @version 03/07/2019 * @param Type */ public abstract
class List { /** * Appends the specified value to the end of this list. * * @para.
Note- Can someone help me with the public boolean isEmpty()- public bo.pdfAugstore
Note: Can someone help me with the public boolean isEmpty(), public boolean contains(Object
o), public int indexOf(Object o) and public E get(int index)methods using abstract List. package
edu.ust.cisc; import java.util.Iterator; public abstract class CiscAbstractList implements CiscList
{ /** * Returns the number of elements in this list. * * @return the number of elements in this
list */ @Override public int size() { int size = 0; Iterator itr = iterator(); while(itr.hasNext()) {
itr.next(); size++; } return size; } /** * Returns {@code true} if this list contains no elements. *
* @return {@code true} if this list contains no elements */ @Override public boolean isEmpty()
{ return false; } /** * Returns {@code true} if this list contains the specified element (compared
using the {@code equals} method). * * @param o element whose presence in this list is to be
tested * @return {@code true} if this list contains the specified element * @throws
NullPointerException if the specified element is null */ @Override public boolean
contains(Object o) { return false; } /** * Returns the index of the first occurrence of the specified
element in this list, or -1 if this list does not * contain the element (compared using the {@code
equals} method). * * @param o element to search for * @return the index of the first occurrence
of the specified element in this list, or -1 if this list does not * contain the element * @throws
NullPointerException if the specified element is null */ @Override public int indexOf(Object o)
{ return 0; } /** * Removes all of the elements from this list. The list will be empty after this call
returns. */ @Override public abstract void clear(); /** * Returns the element at the specified
position in this list. * * @param index index of the element to return * @return the element at
the specified position in this list * @throws IndexOutOfBoundsException if the index is out of
range */ @Override public E get(int index) { return null; } /** * Appends the specified element
to the end of this list. * *
Lists may place the specified element at arbitrary locations if desired. In particular, an ordered
list will * insert the specified element at its sorted location. List classes should clearly specify in
their documentation * how elements will be added to the list if different from the default
behavior (end of this list). * * @param e element to be appended to this list * @return {@code
true} * @throws NullPointerException if the specified element is null */ @Override public
boolean add(E e) { return false; } /** * Replaces the element at the specified position in this list
with the specified element (optional operation). * * @param index index of the element to
replace * @param element element to be stored at the specified position * @return the element
previously at the specified position * @throws UnsupportedOperationException if the {@code
set} operation is not supported by this list * @throws NullPointerException if the specified
el.
Hi,I have added the methods and main class as per your requirement.pdfannaelctronics
Hi,
I have added the methods and main class as per your requirement. it is working fine now.
Highlighted the code changes.
MyLinkedListTest.java
public class MyLinkedListTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MyLinkedList list = new MyLinkedList();
list.addFirst(\"AAAAA\");
list.add(\"1\");
list.add(\"2\");
list.add(\"3\");
list.addLast(\"ZZZZZ\");
System.out.println(\"Linked List Elements : \"+list.toString());
System.out.println(\"First element: \"+list.getFirst());
System.out.println(\"Second element: \"+list.getLast());
System.out.println(\"Removed First Element: \"+list.removeFirst());
System.out.println(\"Now Linked List Elements : \"+list.toString());
System.out.println(\"Removed Last Element: \"+list.removeLast());
System.out.println(\"Now Linked List Elements : \"+list.toString());
System.out.println(\"Removed all element: \");
list.removeAll();
System.out.println(\"Now Linked List Elements : \"+list.toString());
}
}
MyLinkedList.java
public class MyLinkedList extends MyAbstractList {
private Node head, tail;
/** Create a default list */
public MyLinkedList() {
}
/** Create a list from an array of objects */
public MyLinkedList(E[] objects) {
super(objects);
}
/** Return the head element in the list */
public E getFirst() {
if (size == 0) {
return null;
}
else {
return (E)head.element;
}
}
/** Return the last element in the list */
public E getLast() {
if (size == 0) {
return null;
}
else {
return (E)tail.element;
}
}
/** Add an element to the beginning of the list */
public void addFirst(E e) {
Node newNode = new Node(e); // Create a new node
newNode.next = head; // link the new node with the head
head = newNode; // head points to the new node
size++; // Increase list size
if (tail == null) // the new node is the only node in list
tail = head;
}
/** Add an element to the end of the list */
public void addLast(E e) {
Node newNode = new Node(e); // Create a new for element e
if (tail == null) {
head = tail = newNode; // The new node is the only node in list
}
else {
tail.next = newNode; // Link the new with the last node
tail = tail.next; // tail now points to the last node
}
size++; // Increase size
}
/** Add a new element at the specified index in this list
* The index of the head element is 0 */
public void add(int index, E e) {
if (index == 0) {
addFirst(e);
}
else if (index >= size) {
addLast(e);
}
else {
Node current = head;
for (int i = 1; i < index; i++) {
current = current.next;
}
Node temp = current.next;
current.next = new Node(e);
(current.next).next = temp;
size++;
}
}
/** Remove the head node and
* return the object that is contained in the removed node. */
public E removeFirst() {
if (size == 0) {
return null;
}
else {
Node temp = head;
head = head.next;
size--;
if (head == null) {
tail = null;
}
return (E)temp.element;
}
}
/** Remove all elements from list */
public void removeAll() {
while(true) {
if (size == 0) {
break;
}
else {
Node temp = head;
head =.
STAGE 2 The Methods 65 points Implement all the methods t.pdfbabitasingh698417
STAGE 2: The Methods (65 points) Implement all the methods that are marked as Left as
Exercise. The Driver program only works when you have done all the methods. I have added the
template of all the methods with a placeholder value as return types of the methods. For example,
return 0 if method returns an int value.
List of the methods left as exercise are as follows: /** Create a list from an array of objects */
@SuppressWarnings("unchecked") public MyLinkedList(E[] objects) /** Add a new element at the
specified index in this list in ascending order */ public void addInOrder(E e) /** Check to see if this
list contains element e */ public boolean contains(E e) /** Remove all the occurrences of the
element e * from this list. Return true if the element is * removed. */ public boolean removeAll(E e)
/** Remove the first occurrence of the element e * from this list. Return true if the element is *
removed. */ public boolean remove(E e) /** Return the element at the specified index */ public E
get(int index) /** Return the index of the head matching element in * this list. Return -1 if no match.
*/ public int indexOf(Object e) /** Return the index of the last matching element in * this list. Return
-1 if no match. */ public int lastIndexOf(E e) /** Replace the element at the specified position * in
this list with the specified element. */ public E set(int index, E e) /** Print this list using recursion */
public void printList() /** Returns an array containing all of the elements * in this collection; * the
runtime type of the returned array is that of * the specified array. */ public <E> E[] toArray(E[]
array) /** Split the original list in half. The original * list will continue to reference the * front half of
the original list and the method * returns a reference to a new list that stores the * back half of the
original list.
public class MyLinkedList<E extends Comparable<E>> {
private Node<E> head, tail;
private int size = 0; // Number of elements in the list
public MyLinkedList() {
head=tail=null;
size=0;
}
/** Return the head element in the list */
public E getFirst() {
if (size == 0) {
return null;
}
else {
return head.element;
}
}
/** Return the last element in the list */
public E getLast() {
if (size == 0) {
return null;
}
else {
return tail.element;
}
}
/** Add an element to the beginning of the list */
public void addFirst(E e) {
Node<E> newNode = new Node<>(e); // Create a new node
newNode.next = head; // link the new node with the head
head = newNode; // head points to the new node
size++; // Increase list size
if (tail == null) // the new node is the only node in list
tail = head;
}
/** Add an element to the end of the list */
public void addLast(E e) {
Node<E> newNode = new Node<>(e); // Create a new for element e
if (tail == null) {
head = tail = newNode; // The new node is the only node in list
}
else {
tail.next = newNode; // Link the new with the last node
tail = newNode; // tail now points to the last node
}
size++; // Incr.
File LinkedList.java Defines a doubly-l.pdfConint29
File: LinkedList.java
/**
* Defines a doubly-linked list class
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition
* @return the value stored at node first
* @throws NoSuchElementException
*/
public T getFirst() throws NoSuchElementException {
return null;
}
/**
* Returns the value stored in the last node
* @precondition
* @return the value stored in the node last
* @throws NoSuchElementException
*/
public T getLast() throws NoSuchElementException {
return null;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return null;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return -1;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return false;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return false;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition
*/
public void addFirst(T data) {
return;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition
*/
public void addLast(T data) {
return;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
return;
}
/**
* removes the element at the front of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeFirst() throws NoSuchElementException {
return;
}
/**
* removes the element at the end of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeLast() throws NoSuchElementException {
return;
}
/**
* removes the element referenced by the iterator
* @precondition
* @pos.
package ADTs public interface CollectionADTltTgt .pdfsyedabdul78662
package ADTs;
public interface CollectionADT<T> {
public boolean isEmpty();
public int size();
@Override
public String toString();
}
**********************************************************
package ADTs;
import Exceptions.*;
/**
* An interface for an ordered (NOT SORTED) List
* Elements stay in the order they are put in to the list
* For use in Data Structures & Algorithms
*
*
* @author
*/
public interface ListADT<T> extends CollectionADT<T> {
/**
* Adds the specified element to the list at the front
*
* @param element: the element to be added
*
*/
public void addFirst(T element);
/**
* Adds the specified element to the end of the list
*
* @param element: the element to be added
*/
public void addLast(T element);
/**
* Adds the specified element to the list after the existing element
*
* @param existing: the element that is in the list already
* @param element: the element to be added
* @throws ElementNotFoundException if existing isn't in the list
*/
public void addAfter(T existing, T element) throws ElementNotFoundException,
EmptyCollectionException;
/**
* Removes and returns the specified element
*
* @return the element specified
* @throws EmptyCollectionException
* @throws ElementNotFoundException
*/
public T remove(T element) throws EmptyCollectionException, ElementNotFoundException;
/**
* Removes and returns the first element
*
* @return the first element in the list
* @throws EmptyCollectionException
*/
public T removeFirst() throws EmptyCollectionException;
/**
* Removes and returns the last element
*
* @return the last element in the list
* @throws EmptyCollectionException
*/
public T removeLast() throws EmptyCollectionException;
/**
* Returns (without removing) the first element in the list
*
* @return element at the beginning of the list
* @throws EmptyCollectionException
*/
public T first() throws EmptyCollectionException;
/**
* Returns (without removing) the last element in the list
*
* @return element at the end of the list
* @throws EmptyCollectionException
*/
public T last() throws EmptyCollectionException;
/**
* Return whether the list contains the given element.
*
* @param element
* @return
* @throws EmptyCollectionException
*/
public boolean contains(T element) throws EmptyCollectionException;
/**
* Returns the index of the given element.
*
* @param element
* @return the index of the element, or -1 if not found
*/
public int indexOf(T element);
/**
* Return the element at the given index of a list.
*
* @param element
* @return
* @throws EmptyCollectionException
*/
public T get(int index) throws EmptyCollectionException, InvalidArgumentException;
/**
* Set the at the given index of a list.
*
* @param element
* @return
* @throws EmptyCollectionException
*/
public void set(int index, T element) throws EmptyCollectionException, InvalidArgumentException;
}
**********************************************
package ADTs;
import Exceptions.EmptyCollectionException;
import Exceptions.QueueOverflowException;
public interface QueueADT<.
Please complete all the code as per instructions in Java programming.docxcgraciela1
Please complete all the code as per instructions in Java programming import org.w3c.dom.Node; import javax.xml.crypto.NodeSetData; import java.awt.*; import java.util.Iterator; import java.util.NoSuchElementException; /** * This class implements an acyclic (non-cyclic), doubly-linked list. * @param */ public class CiscDoublyLinkedList implements CiscList { /** * A reference to the first node in the list (or null if list is empty). */ private Node head; /** * A reference to the last node int the list (or null if list is empty). */ private Node tail; /** * Number of elements in the list. */ private int size; /** * Returns the number of elements in this list. * * * @return the number of elements in this list */ @Override public int size() { return size; } /** * Returns {@code true} if this list contains no elements. * * * @return {@code true} if this list contains no elements */ @Override public boolean isEmpty() { if (size == 0){ return true; } return false; } /** * Returns {@code true} if this list contains the specified element (compared using the {@code equals} method). * * * @param o element whose presence in this list is to be tested * @return {@code true} if this list contains the specified element * @throws NullPointerException if the specified element is null */ @Override public boolean contains(Object o) { if(o == null) { throw new NullPointerException(); } Node node = head; while(node != null) { if(node.data.equals(o)){ return true; } node = node.next; } return false; } /** * Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not * contain the element (compared using the {@code equals} method). * * * @param o element to search for * @return the index of the first occurrence of the specified element in this list, or -1 if this list does not * contain the element * @throws NullPointerException if the specified element is null */ @Override public int indexOf(Object o) { if (o == null){ throw new NullPointerException(); } for(int i =0; i = size){ throw new IndexOutOfBoundsException(); } return null; } /** * Appends the specified element to the end of this list. * * *
Lists may place the specified element at arbitrary locations if desired. In particular, an ordered list will * insert the specified element at its sorted location. List classes should clearly specify in their documentation * how elements will be added to the list if different from the default behavior (end of this list). * * @param e element to be appended to this list * @return {@code true} * @throws NullPointerException if the specified element is null */ @Override public boolean add(E e) { if(e == null){ throw new NullPointerException(); } return false; } /** * Replaces the element at the specified position in this list with the specified element. * * * @param index index of the element to replace * @param element element to be stored at the specified position * @return the element previously at the specified position *.
please i need help Im writing a program to test the merge sort alg.pdfezonesolutions
please i need help I\'m writing a program to test the merge sort algorithm for linked lists.
I need to Print the list before being sorted and the list after sorting the elements
here is my code only help in test program the four classes are ok except the test program.
TEST PROGRAM
import java.io.*;
import java.util.*;
public class Ch9_ProgExercise7 {
Scanner input = new Scanner(System.in);
public static void main(String[] args) throws IOException {
OrderedLinkedList list
= new OrderedLinkedList(); //Line 1
IntElement num = new IntElement(); //Line 2
// Prompt the user to enter some integers
System.out.println(\"Enter integers numbers \");
String temp = input.hasnextLine();
String[] split = temp.split(\" \");
for (int i = 0; i < split.length; i++) {
Integer a = Integer.parseInt(split[i]);
// insert the intgers into the list you created above
num.setNum(a);
list.insertNode(num);
}
System.out.println();
// Print the list before being sorted
// call the mergesort method
System.out.println();
// print the list after sorting the elements
}
}
ORDEREDLICKEDLIST CLASS
public class OrderedLinkedList extends LinkedListClass
{
//default constructor
public OrderedLinkedList()
{
super();
}
//copy constructor
public OrderedLinkedList(OrderedLinkedList otherList)
{
super(otherList);
}
public void linkedInsertionSort()
{
LinkedListNode lastInOrder;
LinkedListNode firstOutOfOrder;
LinkedListNode current;
LinkedListNode trailCurrent;
lastInOrder = first;
if(first == null)
System.out.println(\"Cannot sort an empty list\");
else
if(first.link == null)
System.out.println(\"The list is of length 1. \"
+ \"Already in order\");
else
while(lastInOrder.link != null)
{
firstOutOfOrder = lastInOrder.link;
if(firstOutOfOrder.info.compareTo(first.info) < 0)
{
lastInOrder.link = firstOutOfOrder.link;
firstOutOfOrder.link = first;
first = firstOutOfOrder;
}
else
{
trailCurrent = first;
current = first.link;
while(current.info.compareTo(firstOutOfOrder.info) < 0)
{
trailCurrent = current;
current = current.link;
}
if(current != firstOutOfOrder)
{
lastInOrder.link = firstOutOfOrder.link;
firstOutOfOrder.link = current;
trailCurrent.link = firstOutOfOrder;
}
else
lastInOrder = lastInOrder.link;
}
}
}//end linkedInsertionSort
//Method to determine whether searchItem is in
//the list.
//Postcondition: Returns true if searchItem is found
// in the list; otherwise, it returns
// false.
public boolean search(DataElement searchItem)
{
LinkedListNode current; //variable to traverse the list
boolean found;
current = first; //set current to point to the first
//node in the list
found = false; //set found to false
while(current != null && !found ) //search the list
if(current.info.compareTo(searchItem) >= 0)
found = true;
else
current = current.link; //make current point to
//the next node
if(found)
found = current.info.equals(searchItem);
return found;
}
//Method to insert insertItem in the list
//Postcondition: first points to the new list,
// newItem is inserted at the proper place
//.
Note- Can someone help me with the private E get(int index- int curren (1).docxVictorzH8Bondx
Note: Can someone help me with the private E get(int index, int currentIndex, Node n)method. The code is not running. Also I need help with the public void add(int index, E element) method too. Please use the parameters provided with the code to solve. package edu.ust.cisc; import java.util.Iterator; import java.util.NoSuchElementException; public class CiscSortedLinkedList > implements CiscList { /** * A reference to this list's dummy node. Its next reference should refer to the node containing the first element * in this list, or it should refer to itself if the list is empty. The next reference within the node containing * the last element in this list should refer to dummy, thus creating a cyclic list. */ private Node dummy; /** * Number of elements in the list. */ private int size; /** * Constructs an empty CiscSortedLinkedList instance with a non-null dummy node whose next reference refers to * itself. */ public CiscSortedLinkedList() { dummy = new Node<>(null, null); dummy.next = dummy; } /** * Returns the number of elements in this list. * * @return the number of elements in this list */ @Override public int size() { return size; } /** * Returns {@code true} if this list contains no elements. * * @return {@code true} if this list contains no elements */ @Override public boolean isEmpty() { return size==0; } /** * Returns {@code true} if this list contains the specified element (compared using the {@code equals} method). * This implementation should stop searching as soon as it is able to determine that the specified element is not * present. * * @param o element whose presence in this list is to be tested * @return {@code true} if this list contains the specified element * @throws NullPointerException if the specified element is null */ @Override public boolean contains(Object o) { if(o==null){ throw new NullPointerException(); } return containsHelper(o,dummy.next); } private boolean containsHelper(Object o, Node node){ if(node== dummy){ return false; } else if(o.equals(node.data)){ return true; } else{ return containsHelper(o,node.next); } } /** * Returns an iterator over the elements in this list in proper sequence. * * @return an iterator over the elements in this list in proper sequence */ @Override public Iterator iterator() { //return new Iterator (){ //private Node curr = dummy.next; //private Node prev = dummy; //private boolean canRemove = false; return null; } /** * Returns an array containing all of the elements in this list in proper sequence (from first to last element). *
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, * this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify * the returned array. * * @return an array containing all of the elements in this list in proper sequence */ @Override public Object[] toArray() { Object[] arr = new Object[size]; int i = 0; for(Node current = dummy;current!=null;cur.
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...John Andrews
SlideShare Description for "Chatty Kathy - UNC Bootcamp Final Project Presentation"
Title: Chatty Kathy: Enhancing Physical Activity Among Older Adults
Description:
Discover how Chatty Kathy, an innovative project developed at the UNC Bootcamp, aims to tackle the challenge of low physical activity among older adults. Our AI-driven solution uses peer interaction to boost and sustain exercise levels, significantly improving health outcomes. This presentation covers our problem statement, the rationale behind Chatty Kathy, synthetic data and persona creation, model performance metrics, a visual demonstration of the project, and potential future developments. Join us for an insightful Q&A session to explore the potential of this groundbreaking project.
Project Team: Jay Requarth, Jana Avery, John Andrews, Dr. Dick Davis II, Nee Buntoum, Nam Yeongjin & Mat Nicholas
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Subhajit Sahu
Abstract — Levelwise PageRank is an alternative method of PageRank computation which decomposes the input graph into a directed acyclic block-graph of strongly connected components, and processes them in topological order, one level at a time. This enables calculation for ranks in a distributed fashion without per-iteration communication, unlike the standard method where all vertices are processed in each iteration. It however comes with a precondition of the absence of dead ends in the input graph. Here, the native non-distributed performance of Levelwise PageRank was compared against Monolithic PageRank on a CPU as well as a GPU. To ensure a fair comparison, Monolithic PageRank was also performed on a graph where vertices were split by components. Results indicate that Levelwise PageRank is about as fast as Monolithic PageRank on the CPU, but quite a bit slower on the GPU. Slowdown on the GPU is likely caused by a large submission of small workloads, and expected to be non-issue when the computation is performed on massive graphs.
Techniques to optimize the pagerank algorithm usually fall in two categories. One is to try reducing the work per iteration, and the other is to try reducing the number of iterations. These goals are often at odds with one another. Skipping computation on vertices which have already converged has the potential to save iteration time. Skipping in-identical vertices, with the same in-links, helps reduce duplicate computations and thus could help reduce iteration time. Road networks often have chains which can be short-circuited before pagerank computation to improve performance. Final ranks of chain nodes can be easily calculated. This could reduce both the iteration time, and the number of iterations. If a graph has no dangling nodes, pagerank of each strongly connected component can be computed in topological order. This could help reduce the iteration time, no. of iterations, and also enable multi-iteration concurrency in pagerank computation. The combination of all of the above methods is the STICD algorithm. [sticd] For dynamic graphs, unchanged components whose ranks are unaffected can be skipped altogether.
2. The List Interface
Method: void add(int index, Object o)
Inserts specified element at specified position
Example:
list.add(4, a); //adds element a at position 4
3. The List Interface
Method: boolean add(Object o)
Adds specified element to the end of the list
Example:
list.add(a); //adds element a at the end of the list
4. The List Interface
Method: boolean contains(Object 0)
Returns true if the specified element is in the list
Example:
list.add(a);
list.contains(a); //returns true
////////////////////////////////////////////////////////////
list.add(b);
list.contains(a); //returns false
5. The List Interface
Method: Object get(int index)
Returns the element at the specified position
Example:
list.add(a);
list.add(b);
list.get(1); //returns b
6. The List Interface
Method: int indexOf(object o);
Returns the index of the specified element or else -1
Example:
list.add(a);
list.add(b);
list.add(c);
list.indexOf(c); //returns 2
7. The List Interface
Method: int lastIndexOf(object o);
Returns the last index of the specified element or
else -1
Example:
list.add(a);
list.add(b);
list.add(a);
list.indexOf(a); //returns 2
8. The List Interface
Method: Object remove(int index)
Removes the element at the specified index
Example:
list.add(a);
list.add(b);
list.add(c);
list.remove(1); //removes element a
9. The List Interface
Method: boolean remove(Object o)
Removes the first occurrence of the specified element
Example:
list.add(a);
list.add(b);
list.add(a);
list.remove(a); //removes element a at position 0
10. The List Interface
Method: object set(int index, Object element)
Replaces the element at the specified position and
returns the old element
Example:
list.add(a);
list.set(0, b); //replaces element a with b and
returns element a
11. The List Interface
Method: boolean isEmpty()
Returns true if the method is empty
Example
list.isEmpty(); //retruns true
////////////////////////////////////////////////////////////
list.add(a);
list.isEmpty(); //returns false
12. The List Interface
Method: int size()
Returns the number of elements in the list
Example:
list.add(a);
list.add(b);
list.add(c);
list.size(); //Returns 3
13. The List Interface
Method: boolean addAll(Collection c)
Appends all the elements in the specified collection to
the end of the list
Example:
list2.add(a);
list2.add(b);
list2.add(c);
list.addAll(list); //adds all elements in list2 to
list
14. The List Interface
Method: boolean addAll(int index, Collection c)
Appends all the elements in the specified collection to
the specified position
Example:
list2.add(a);
list2.add(b);
list.add(a);
list.addAll(0,list); //adds all elements in list2 to
list before element a
15. The List Interface
Method: void clear()
Removes all elements from the list
Example:
list.add(a);
list.add(b);
list.clear(); //removes elements a and b
16. The List Interface
Methods: boolean conatainsAll(Collection c)
Returns true if the list contains all the element in the
collection
Example:
list2.add(a);
list2.add(b);
list.add(a);
list.add(b);
list2.containAll(list); //Returns true
17. The List Interface
Method: equals(Object o)
Compares the specific object with the list for equality
Example
list.add(a);
list2.add(a);
list.equals(list2); //Returns true
///////////////////////////////////////////////////////////////////////////////
list.add(a);
list2.add(b);
list.equals(list2); //Returns false
18. The List Interface
Method: Iterator iterator()
Returns an iterator over the elements in the list in
proper sequence
Example
Iterator iter = list.iterator(); //Creates an
iterator for list
19. The List Interface
Method: ListIterator listIterator()
Returns a list iterator over the elements in the list in
proper sequence
Example
ListIterator iter = list.listIterator(); //Creates a
list iterator
20. The List Interface
Method: ListIterator listIterator(int index)
Returns a list iterator over the elements in the list in
proper sequence, starting at the indicated position
Example
ListIterator iter = list.listIterator(2); //Creates
a list iterator starting at 2
21. The List Interface
Method: boolean removeAll(collection c)
Removes all of the elements specified from the list
Example
list2.add(a);
list2.add(b);
list2.add(c);
list.add(a);
list.add(b);
list2.removeAll(list); //Removes elements a and
b
22. The List Interface
Method: boolean retainAll(collection c)
Retains only the elements specified in the list
Example
list2.add(a);
list2.add(b);
list2.add(c);
list.add(a);
list2.retainAll(list); //Removes elements b and c
and keeps a
23. The List Interface
Method: List subList(int fromIndex, int toIndex)
Returns a view of the portion of the list between the
specified indexes
Example
list.add(a);
list.add(b);
list.add(c);
list.add(d);
list.subList(1,3); //returns a view of elements
b,c,d
24. The List Interface
Method: Object[] toArray()
Returns an array containg all of the elements in the
list
Example:
list.add(1);
list.add(2);
list.add(3);
int[] array = list.toArray(); //Creates an array
conating all of lists elements: 1, 2, and 3
25. The List Interface
Method: Object[] toArray(Object a)
Returns an array containg all of the elements in the
list, witht the runtime/ size of the array according to
the object
Example:
list.add(1);
list.add(2);
list.add(3);
int[] array = list.toArray(list); //Creats an array
conating all of lists elements: 1, 2, and 3 with size of list
26. Iterator Interface
Method: boolean hasNext()
Returns true if there are any items in the next position
Example:
While(iter.hasNext()) //Checks if there is a next
position
iter.next();
27. Iterator Interface
Method: Object next()
Returns the next item and moves to the next position
if hasNext is true
Example:
While(iter.hasNext())
iter.next(); //moves the position of the
array to the next spot
28. Iterator Interface
Method: void remove()
Removes item returned by the most recent call of next
Example:
While(iter.hasNext())
iter.next();
iter.remove(); //clears the list
29. Iterator Interface
Method: boolean hasPrevious()
Returns true if there are any items in the previous
position
Example:
While(iter.hasPrevious()) //Checks if there is a
previous position
iter.previous();
30. Iterator Interface
Method: Object previous()
Returns the previous item and moves to the position
before the current location if hasPrevious is true
Example:
While(iter.hasPrevious())
iter.previous(); //moves the position of
the array to the previous spot
31. Iterator Interface
Method: Object nextIndex()
Returns the value of the next index or -1 if none
Example:
list.add(a);
list.add(b);
ListIterator iter = list.listIterator();
iter.nextIndex(); //returns b
/////////////////////////////////////////////////////////////////
list.add(a);
ListIterator iter = list.listIterator();
iter.nextIndex(); //returns -1
32. Iterator Interface
Method: Object previousIndex()
Returns the value of the previous index or -1 if none
Example:
list.add(a);
ListIterator iter = list.listIterator();
iter.previousIndex(); //returns -1
/////////////////////////////////////////////////////////////////
list.add(a);
list.add(b);
iter.next();
ListIterator iter = list.listIterator();
iter.previousIndex(); //returns a
33. Iterator Interface
Method: void add(Object 0)
Inserts an object o at the current pposition
Example:
list.add(a);
list.add(b);
ListIterator iter = list.listIterator();
iter.add(z); // list looks like (z,a,b)
34. Iterator Interface
Method: void set(Object o)
Replaces the last item returned by next or previous
Example:
list.add(a);
list.add(b);
ListIterator iter = list.listIterator();
iter.next();
iter.set(z); //List looks like (a,z)