Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Iterator;
- import java.util.NoSuchElementException;
- import java.lang.Integer;
- class SLL<E extends Number> implements Comparable<E>
- {
- private SLLNode<E> first;
- public SLL()
- {
- this.first = null;
- }
- public SLLNode<E> getFirst() {
- return first;
- }
- public void setFirst(SLLNode<E> first) {
- this.first = first;
- }
- public void insertFirst(E o)
- {
- SLLNode<E> ins = new SLLNode<E>(o, first);
- first = ins;
- }
- public void insertLast(E o)
- {
- if(first != null)
- {
- SLLNode<E> tmp = first;
- while(tmp.succ != null)
- tmp = tmp.succ;
- SLLNode<E> ins = new SLLNode<E>(o,null);
- tmp.succ = ins;
- }
- else
- {
- insertFirst(o);
- }
- }
- public SLL<E> joinLists(SLL<E> lista2)
- {
- SLL<E> rezultat = new SLL<E>();
- SLLNode<E> jazol1 = this.getFirst();
- SLLNode<E> jazol2 = lista2.getFirst();
- while(jazol1 != null && jazol2 !=null)
- {
- if(jazol1.getElement().compareTo(jazol2.getElement()) < 0)
- {
- }
- }
- }
- @Override
- public int compareTo(E o) {
- // TODO Auto-generated method stub
- return 0;
- }
- }
- class SLLNode<E>
- {
- protected E element;
- protected SLLNode<E> succ;
- public E getElement() {
- return element;
- }
- public void setElement(E element) {
- this.element = element;
- }
- public SLLNode<E> getSucc() {
- return succ;
- }
- public void setSucc(SLLNode<E> succ) {
- this.succ = succ;
- }
- public SLLNode(E element, SLLNode<E> succ) {
- super();
- this.element = element;
- this.succ = succ;
- }
- }
- /*class JoinSortedLists<E> extends SLL<E>
- {
- public SLL<E> joinLists(SLL<E> lista2)
- {
- SLL<E> rezultat = new SLL<E>();
- SLLNode<E> jazol1 = this.getFirst();
- SLLNode<E> jazol2 = lista2.getFirst();
- while(jazol1 != null && jazol2 !=null)
- {
- {
- }
- }
- }
- }*/
- public class SLLJoinLists {
- public static void main(String[] args) throws IOException {
- SLL<E> lista1 = new SLL<E>();
- SLL<E> lista2 = new SLL<E>();
- BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
- String s = stdin.readLine();
- int N = Integer.parseInt(s);
- s = stdin.readLine();
- String[] pomniza = s.split(" ");
- for (int i = 0; i < N; i++) {
- lista1.insertLast(Integer.parseInt(pomniza[i]));
- }
- s = stdin.readLine();
- N = Integer.parseInt(s);
- s = stdin.readLine();
- pomniza = s.split(" ");
- for (int i = 0; i < N; i++) {
- lista2.insertLast(Integer.parseInt(pomniza[i]));
- }
- // spoeni = lista1.joinLists(lista2);
- Iterator<Integer> it = spoeni.iterator();
- while (it.hasNext()) {
- System.out.print(it.next());
- if(it.hasNext())
- System.out.print(" ");
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment