Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>just to give you a start...</p> <pre><code>public YourLinkedList splitToSequences(int[] array) { YourLinkedList list = new YourLinkedList(); if(array.length &gt; 0) { YourSequence sequence = new YourSequence(); int currentNumber; int lastNumber = array[0]; sequence.add(lastNumber); for(int index = 1; index &lt; array.length; index++) { currentNumber = array[index]; if(currentNumber != lastNumber + 1) { // curentNumber breaks the sequence list.add(sequence); // save the old sequence to list sequence = new YourSequence(); // and start a new one } sequence.add(currentNumber); } list.add(sequence); } return list; } </code></pre> <p>Now go and figure out your linked list and sequence classes and do the printing stuff...</p> <p>A minimalistic implementation of a linked list</p> <pre><code>public class MyLinkedList&lt;T1&gt; { private MyLinkedListItem&lt;T1&gt; first = null; private MyLinkedListItem&lt;T1&gt; last = null; public MyLinkedList() { } public void add(T1 item) { MyLinkedListItem&lt;T1&gt; newItem = new MyLinkedListItem&lt;T1&gt;(item); if (first == null) { first = newItem; } else { last.setNext(newItem); } last = newItem; } @Override public String toString() { StringBuffer buffer = new StringBuffer(); if(first != null) { MyLinkedListItem&lt;T1&gt; current = first; while(current.hasNext()) { buffer.append(current.toString()); buffer.append(" -&gt; "); current = current.getNext(); } buffer.append(current.toString()); } return buffer.toString(); } private class MyLinkedListItem&lt;T2&gt; { private T2 data; private MyLinkedListItem&lt;T2&gt; next = null; public MyLinkedListItem(T2 data) { this.data = data; } public boolean hasNext() { return next != null; } public MyLinkedListItem&lt;T2&gt; getNext() { return next; } public void setNext(MyLinkedListItem&lt;T2&gt; next) { this.next = next; } @Override public String toString() { return data.toString(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload