Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class linkedlist {
- public static node head = new node();
- public static void add(int index, object element){
- node n = new node();
- node cur = head;
- n.polynomial = element;
- for (int i = 0; i < index-1; ++i)
- cur = cur.next;
- n = cur.next;
- cur.next = n;
- }
- public static void add(object element){
- node newNode = new node();
- node cur = head;
- newNode.polynomial = element;
- while(cur.next != null)
- cur = cur.next;
- newNode.next = null;
- cur.next = newNode;
- }
- public object get(int index){
- node cur = head;
- for (int i = 0; i < index; ++i)
- cur = cur.next;
- return cur.polynomial;
- }
- public void set(int index, object element){
- node cur = head;
- for (int i = 0; i < index; ++i)
- cur = cur.next;
- cur.polynomial = element;
- }
- public void clear(){
- head = null;
- }
- public boolean isEmpty(){
- if(head == null)
- return true;
- return false;
- }
- public void remove(int index){
- node cur = head;
- for (int i = 0; i < index-1; ++i)
- cur = cur.next;
- cur.next = cur.next.next;
- }
- public int size(){
- node cur = head;
- int counter = 0;
- while (cur != null){
- cur = cur.next;
- counter++;
- }
- return counter;
- }
- public linkedlist sublist(int fromIndex, int toIndex){
- linkedlist newLinked = null;
- node cur = head;
- for (int i = 0; i < fromIndex && cur != null; ++i)
- cur = cur.next;
- node Ncur = newLinked.head;
- Ncur.polynomial = cur.polynomial;
- for(int i = fromIndex; i < toIndex && cur != null; ++i){
- node n = new node();
- n.polynomial = cur.polynomial;
- cur = cur.next;
- Ncur.next = n;
- Ncur = Ncur.next;
- }
- Ncur.next = null;
- return newLinked;
- }
- public boolean contian(object o){
- node cur = head;
- while(cur != null){
- if(cur.polynomial == o)
- return true;
- cur = cur.next;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement