diff --git a/group22/735371210/.gitignore b/group22/735371210/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group22/735371210/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group22/735371210/.project b/group22/735371210/.project new file mode 100644 index 0000000000..1e6bc81917 --- /dev/null +++ b/group22/735371210/.project @@ -0,0 +1,17 @@ + + + task1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group22/735371210/src/task1/basic/Iterator.java b/group22/735371210/src/task1/basic/Iterator.java new file mode 100644 index 0000000000..ceed20b8ae --- /dev/null +++ b/group22/735371210/src/task1/basic/Iterator.java @@ -0,0 +1,8 @@ +package task1.basic; + +public interface Iterator { + + public boolean hasNext(); + public Object next(); + +} diff --git a/group22/735371210/src/task1/basic/LinkedList.java b/group22/735371210/src/task1/basic/LinkedList.java new file mode 100644 index 0000000000..02177df4ea --- /dev/null +++ b/group22/735371210/src/task1/basic/LinkedList.java @@ -0,0 +1,140 @@ +package task1.basic; + +public class LinkedList implements List{ + + private Node head = new Node(); + private int size; + + private static class Node{ + Object data; + Node next; + } + + + public void add(Object o){ + addLast(o); + + } + public void add(int index ,Object o){ + if(index<0 || index>size -1){ + throw new ArrayIndexOutOfBoundsException(); + } + + Node node=head; + + Node newNode=new Node(); + + for(int i =0;ielementData.length){ + grow(minLength); + + } + } + + public void grow(int minLength){ + + int oldLength = elementData.length; + int newLength = oldLength + oldLength>>1; + + if(newLength < minLength){ + newLength=minLength; + } + + elementData= Arrays.copyOf(elementData, newLength); + + + + } + public void add(int index ,Object o){ + checkLength(size+1); + System.arraycopy(elementData, index, elementData, index+1, size-index); + elementData[index]=o; + size++; + + } + public Object get(int index){ + + return elementData[index]; + + + } + public Object remove(int index){ + + Object element=elementData[index]; + + System.arraycopy(elementData, index+1, elementData, index, size-index-1); + + elementData[size-1]=null; + + size--; + + return element; + } + + public int size(){ + + return size; + } + + public Iterator iterator(){ + return new ArrayListIterator(); + } + + class ArrayListIterator implements Iterator{ + + int pos=0; + + public boolean hasNext(){ + + if(elementData[pos]!=null){ + return true; + } + + return false; + + } + + public Object next(){ + + return elementData[pos++]; + } + + } + public static void main(String[] args){ + MyArrayList my=new MyArrayList(); + my.add(0); + my.add(1); + my.add(2,10); + my.add(1,11); + my.add(3,32); + + Object ele=my.remove(2); + + System.out.println(ele); + System.out.println(my.get(1)); + System.out.println(my.size()); + + System.out.println("---------"); + + Iterator it=my.iterator(); + while(it.hasNext()){ + System.out.println(it.next()); + } + + + + } + +} diff --git a/group22/735371210/src/task1/basic/Queue.java b/group22/735371210/src/task1/basic/Queue.java new file mode 100644 index 0000000000..7ade2226c4 --- /dev/null +++ b/group22/735371210/src/task1/basic/Queue.java @@ -0,0 +1,45 @@ +package task1.basic; + +import java.util.LinkedList; + +public class Queue { + + private LinkedList q=new LinkedList(); + + public void enQueue(Object o){ + + q.addLast(o); + } + + public Object deQueue(){ + return q.removeFirst(); + + } + + public int size(){ + + return q.size(); + } + + public static void main(String[] args){ + Queue testQ= new Queue(); + + testQ.enQueue(11); + testQ.enQueue(12); + + testQ.enQueue(13); + + System.out.println(testQ.size()); + + Object s1=testQ.deQueue(); + System.out.println(s1); + + Object s2=testQ.deQueue(); + System.out.println(s2); + + + + + } + +} diff --git a/group22/735371210/src/task1/basic/Stack.java b/group22/735371210/src/task1/basic/Stack.java new file mode 100644 index 0000000000..8aa7d2c5c1 --- /dev/null +++ b/group22/735371210/src/task1/basic/Stack.java @@ -0,0 +1,40 @@ +package task1.basic; + +import java.util.ArrayList; +public class Stack { + + private ArrayList elementData =new ArrayList(); + + public void push(Object o){ + + elementData.add(o); + } + + public Object pop(){ + + return elementData.remove(size()-1); + + } + + public boolean isEmpty(){ + return elementData.isEmpty(); + + } + + public Object peek(){ + + return elementData.get(size()-1); + + + } + + public int size(){ + return elementData.size(); + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +}