diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..37750fd
Binary files /dev/null and b/.DS_Store differ
diff --git a/Alternatives.launch b/Alternatives.launch
new file mode 100644
index 0000000..0b299f5
--- /dev/null
+++ b/Alternatives.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Anagram.launch b/Anagram.launch
new file mode 100644
index 0000000..cde08bc
--- /dev/null
+++ b/Anagram.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Duplicate_number.launch b/Duplicate_number.launch
new file mode 100644
index 0000000..dae5cb9
--- /dev/null
+++ b/Duplicate_number.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Implementation.launch b/Implementation.launch
new file mode 100644
index 0000000..25703a9
--- /dev/null
+++ b/Implementation.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Implementations.launch b/Implementations.launch
new file mode 100644
index 0000000..1887e2c
--- /dev/null
+++ b/Implementations.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Lists.launch b/Lists.launch
new file mode 100644
index 0000000..ccba8df
--- /dev/null
+++ b/Lists.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/New_configuration.launch b/New_configuration.launch
new file mode 100644
index 0000000..110eb1e
--- /dev/null
+++ b/New_configuration.launch
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Practice.launch b/Practice.launch
new file mode 100644
index 0000000..824ed72
--- /dev/null
+++ b/Practice.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Problem1.launch b/Problem1.launch
new file mode 100644
index 0000000..5e49323
--- /dev/null
+++ b/Problem1.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Problem_stock_are_profitable.launch b/Problem_stock_are_profitable.launch
new file mode 100644
index 0000000..4bb2f42
--- /dev/null
+++ b/Problem_stock_are_profitable.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Question.launch b/Question.launch
new file mode 100644
index 0000000..4b706be
--- /dev/null
+++ b/Question.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Question1.launch b/Question1.launch
new file mode 100644
index 0000000..eddf12b
--- /dev/null
+++ b/Question1.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/StackPractice.launch b/StackPractice.launch
new file mode 100644
index 0000000..8388541
--- /dev/null
+++ b/StackPractice.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Test (1).launch b/Test (1).launch
new file mode 100644
index 0000000..89bbdb3
--- /dev/null
+++ b/Test (1).launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Test.launch b/Test.launch
new file mode 100644
index 0000000..fb478c8
--- /dev/null
+++ b/Test.launch
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/comparatorsAndComparables/MainClass.java b/comparatorsAndComparables/MainClass.java
index d222235..ba6326c 100644
--- a/comparatorsAndComparables/MainClass.java
+++ b/comparatorsAndComparables/MainClass.java
@@ -5,6 +5,7 @@
public class MainClass {
public static void main(String[] args) {
+<<<<<<< HEAD
List students = new ArrayList<>();
@@ -80,10 +81,49 @@ public int compare(Student o1, Student o2) {
// IF WE WANT TO REVERSE THE DEFINED SORTING ORDER WE CAN USE "reversed"
// function
Collections.sort(students, Comparator.comparing(Student::getName).thenComparing(Student::getMarks).reversed());
+=======
+
+ List students = new ArrayList<>();
+
+ students.add(new Student(23, "Ram"));
+ students.add(new Student(35, "Shyam"));
+ students.add(new Student(83, "Aman"));
+ students.add(new Student(13, "Ram"));
+ students.add(new Student(13, "Anuj"));
+
+// Collections.sort(students, new Comparator() {
+//
+// @Override
+// public int compare(Student o1, Student o2) {
+// if(o1.name.equals(o2.name)) {
+// return o1.marks - o2.marks;
+// } else {
+// return o1.name.compareTo(o2.name);
+// }
+// }
+//
+// });
+//
+// Collections.sort(students, (o1, o2) -> {
+// if(o1.name.equals(o2.name)) {
+// return o1.marks - o2.marks;
+// } else {
+// return o1.name.compareTo(o2.name);
+// }
+// });
+
+// Collections.sort(students, (o1, o2) -> o1.name.compareTo(o2.name));
+
+ Collections.sort(students, Comparator.comparing(Student::getName)
+ .thenComparing(Student::getMarks).reversed());
+
+ students.forEach(System.out::println);
+>>>>>>> 24de017... Initial commit
}
}
+<<<<<<< HEAD
// COMPARATORS CLASS
class SortByNameThenMarks implements Comparator {
@@ -98,3 +138,17 @@ public int compare(Student o1, Student o2) {
}
}
+=======
+//class SortByNameThenMarks implements Comparator{
+//
+// @Override
+// public int compare(Student o1, Student o2) {
+// if(o1.name.equals(o2.name)) {
+// return o1.marks - o2.marks;
+// } else {
+// return o1.name.compareTo(o2.name);
+// }
+// }
+//
+//}
+>>>>>>> 24de017... Initial commit
diff --git a/comparatorsAndComparables/Student.java b/comparatorsAndComparables/Student.java
index a736bed..6fe3c2e 100644
--- a/comparatorsAndComparables/Student.java
+++ b/comparatorsAndComparables/Student.java
@@ -1,10 +1,17 @@
package comparatorsAndComparables;
public class Student {
+<<<<<<< HEAD
int marks;
String name;
+=======
+
+ int marks;
+ String name;
+
+>>>>>>> 24de017... Initial commit
public Student(int marks, String name) {
super();
this.marks = marks;
@@ -32,6 +39,10 @@ public void setName(String name) {
this.name = name;
}
+<<<<<<< HEAD
+=======
+
+>>>>>>> 24de017... Initial commit
public int compareTo(Student obj) {
return this.marks - obj.marks;
}
diff --git a/deque/MainClass.java b/deque/MainClass.java
index 14f2b3f..fa87e25 100644
--- a/deque/MainClass.java
+++ b/deque/MainClass.java
@@ -5,6 +5,7 @@
public class MainClass {
public static void main(String[] args) {
+<<<<<<< HEAD
ArrayDeque ad = new ArrayDeque<>();
@@ -15,6 +16,18 @@ public static void main(String[] args) {
System.out.println(ad.pop());
System.out.println(ad.pop());
+=======
+
+ ArrayDeque ad = new ArrayDeque<>();
+
+ ad.push(12);
+ ad.push(23);
+ ad.push(34);
+
+ System.out.println(ad.pop());
+ System.out.println(ad.pop());
+
+>>>>>>> 24de017... Initial commit
}
}
diff --git a/deque/MyDeque.java b/deque/MyDeque.java
index 3567ffc..0965a7f 100644
--- a/deque/MyDeque.java
+++ b/deque/MyDeque.java
@@ -1,6 +1,7 @@
package deque;
public class MyDeque {
+<<<<<<< HEAD
Node head, tail;
@@ -21,21 +22,56 @@ public E removeLast() {
}
Node toRemove = tail;
if (tail.next == null) {
+=======
+
+ Node head, tail;
+
+ public void addToHead(E data) {
+ Node toAdd = new Node<>(data);
+ if(head == null) {
+ head = tail = toAdd;
+ }
+ else {
+ head.next = toAdd;
+ toAdd.prev = head;
+ head = head.next;
+ }
+ }
+
+ public E removeLast() {
+ if(head == null) {
+ return null;
+ }
+ Node toRemove = tail;
+ if(tail.next == null) {
+>>>>>>> 24de017... Initial commit
tail = head = null;
return toRemove.data;
}
tail = tail.next;
tail.prev = null;
+<<<<<<< HEAD
if (tail == null) {
+=======
+ if(tail == null) {
+>>>>>>> 24de017... Initial commit
head = null;
}
return toRemove.data;
}
+<<<<<<< HEAD
public static class Node {
E data;
Node next, prev;
+=======
+
+ public static class Node {
+ E data;
+ Node next, prev;
+
+>>>>>>> 24de017... Initial commit
public Node(E data) {
this.data = data;
this.next = this.prev = null;
diff --git a/interfaces/Person.java b/interfaces/Person.java
index 7835686..c631be3 100644
--- a/interfaces/Person.java
+++ b/interfaces/Person.java
@@ -3,11 +3,19 @@
public class Person implements Student, YouTuber {
public static void main(String[] args) {
+<<<<<<< HEAD
Person obj = new Person();
obj.makeVideo();
obj.study();
+=======
+
+ Person obj = new Person();
+ obj.makeVideo();
+ obj.study();
+
+>>>>>>> 24de017... Initial commit
YouTuber x = obj;
x.makeVideo();
@@ -15,16 +23,30 @@ public static void main(String[] args) {
@Override
public void makeVideo() {
+<<<<<<< HEAD
System.out.println("person is making video");
+=======
+
+ System.out.println("person is making video");
+
+>>>>>>> 24de017... Initial commit
}
@Override
public void study() {
+<<<<<<< HEAD
System.out.println("person is studying");
}
+=======
+
+ System.out.println("person is studying");
+
+ }
+
+>>>>>>> 24de017... Initial commit
}
diff --git a/interfaces/Student.java b/interfaces/Student.java
index d044713..17c6925 100644
--- a/interfaces/Student.java
+++ b/interfaces/Student.java
@@ -3,5 +3,9 @@
public abstract interface Student {
abstract void study();
+<<<<<<< HEAD
+=======
+
+>>>>>>> 24de017... Initial commit
}
diff --git a/interfaces/YouTuber.java b/interfaces/YouTuber.java
index 057b380..85a00cc 100644
--- a/interfaces/YouTuber.java
+++ b/interfaces/YouTuber.java
@@ -3,5 +3,9 @@
public abstract interface YouTuber {
abstract void makeVideo();
+<<<<<<< HEAD
+=======
+
+>>>>>>> 24de017... Initial commit
}
diff --git a/interviewQuestions/GroupAnagrams.java b/interviewQuestions/GroupAnagrams.java
index 6f34179..dbdf1d8 100644
--- a/interviewQuestions/GroupAnagrams.java
+++ b/interviewQuestions/GroupAnagrams.java
@@ -1,6 +1,7 @@
package interviewQuestions;
import java.util.*;
+<<<<<<< HEAD
public class GroupAnagrams {
@@ -27,6 +28,33 @@ public static List> groupAnagrams(String[] strs) {
map.put(key, list);
}
+=======
+public class GroupAnagrams {
+
+ public static void main(String[] args) {
+ String strs[] = {"eat", "tea", "tan", "ate", "nat", "bat"};
+ List> ans = groupAnagrams(strs);
+
+ for(List list: ans) {
+ System.out.println(list);
+ }
+ }
+
+ public static List> groupAnagrams(String[] strs) {
+ Map> map = new HashMap<>();
+ for(String s: strs) {
+ int count[] = new int[26];
+ for(int i = 0; i list = map.getOrDefault(key, new LinkedList());
+
+ list.add(s);
+ map.put(key, list);
+ }
+
+>>>>>>> 24de017... Initial commit
return new LinkedList<>(map.values());
}
}
\ No newline at end of file
diff --git a/interviewQuestions/SlidingWindowMaximum.java b/interviewQuestions/SlidingWindowMaximum.java
index c090ed5..91e0fb7 100644
--- a/interviewQuestions/SlidingWindowMaximum.java
+++ b/interviewQuestions/SlidingWindowMaximum.java
@@ -1,5 +1,8 @@
package interviewQuestions;
+<<<<<<< HEAD
+=======
+>>>>>>> 24de017... Initial commit
import java.util.*;
public class SlidingWindowMaximum {
@@ -7,15 +10,24 @@ public class SlidingWindowMaximum {
public static void main(String[] args) {
Solution solution = new Solution();
+<<<<<<< HEAD
int a[] = { 4, 3, 1, 2, 5, 3, 4, 7, 1, 9 };
int ans[] = solution.maxSlidingWindow(a, 4);
for (int x : ans) {
System.out.print(x + " ");
+=======
+ int a[] = {4, 3, 1, 2, 5, 3, 4, 7, 1, 9};
+ int ans[] = solution.maxSlidingWindow(a, 4);
+
+ for(int x: ans) {
+ System.out.print(x+" ");
+>>>>>>> 24de017... Initial commit
}
}
static class Solution {
+<<<<<<< HEAD
public int[] maxSlidingWindow(int[] a, int k) {
int n = a.length;
@@ -69,5 +81,48 @@ public int[] maxSlidingWindow(int[] a, int k) {
// Returning the ans Array.
return ans;
}
+=======
+ public int[] maxSlidingWindow(int[] a, int k) {
+ int n = a.length;
+ Deque dq = new LinkedList<>();
+ int ans[] = new int[n-k+1];
+
+ int i = 0;
+ for(; i>>>>>> 24de017... Initial commit
}
}
diff --git a/interviewQuestions/SubarrayWithZeroSum.java b/interviewQuestions/SubarrayWithZeroSum.java
index 2d52b2d..a8dce71 100644
--- a/interviewQuestions/SubarrayWithZeroSum.java
+++ b/interviewQuestions/SubarrayWithZeroSum.java
@@ -6,6 +6,7 @@
*/
import java.util.*;
+<<<<<<< HEAD
public class SubarrayWithZeroSum {
@@ -33,13 +34,47 @@ public static void main(String[] args) {
set.add(sum);
sum += element;
if (set.contains(sum - k)) {
+=======
+public class SubarrayWithZeroSum {
+
+ public static void main(String[] args) {
+
+ int[] a = {2, 1, 3, -4, -2};
+ int k = -3;
+ boolean found = false;
+
+// for(int i = 0; i set = new HashSet<>();
+ int sum = 0;
+ for(int element : a) {
+ set.add(sum);
+ sum += element;
+ if(set.contains(sum-k)) {
+>>>>>>> 24de017... Initial commit
found = true;
break;
}
}
+<<<<<<< HEAD
System.out.println("found " + found);
+=======
+
+ System.out.println("found "+ found);
+
+>>>>>>> 24de017... Initial commit
}
}
diff --git a/linkedLists/MainLinkedList.java b/linkedLists/MainLinkedList.java
index 55184e2..bef4ad8 100644
--- a/linkedLists/MainLinkedList.java
+++ b/linkedLists/MainLinkedList.java
@@ -5,6 +5,7 @@
public class MainLinkedList {
public static void main(String[] args) {
+<<<<<<< HEAD
MyLinkedList myLL = new MyLinkedList();
@@ -12,7 +13,20 @@ public static void main(String[] args) {
myLL.add(i + "added");
}
+=======
+
+ MyLinkedList myLL = new MyLinkedList();
+
+ for(int i = 0; i<10; i++) {
+ myLL.add(i+"added");
+ }
+
+>>>>>>> 24de017... Initial commit
myLL.print();
}
}
+<<<<<<< HEAD
+=======
+
+>>>>>>> 24de017... Initial commit
diff --git a/linkedLists/MyLinkedList.java b/linkedLists/MyLinkedList.java
index 30d2078..e59820e 100644
--- a/linkedLists/MyLinkedList.java
+++ b/linkedLists/MyLinkedList.java
@@ -3,6 +3,7 @@
public class MyLinkedList {
Node head;
+<<<<<<< HEAD
public void add(E data) {
Node toAdd = new Node(data);
@@ -14,10 +15,24 @@ public void add(E data) {
Node temp = head;
while (temp.next != null) {
+=======
+
+ public void add(E data) {
+ Node toAdd = new Node(data);
+
+ if(isEmpty()) {
+ head = toAdd;
+ return;
+ }
+
+ Node temp = head;
+ while(temp.next != null) {
+>>>>>>> 24de017... Initial commit
temp = temp.next;
}
temp.next = toAdd;
}
+<<<<<<< HEAD
void print() {
Node temp = head;
@@ -39,18 +54,47 @@ public E removeLast() throws Exception {
}
if (temp.next == null) {
+=======
+
+ void print() {
+ Node temp = head;
+ while(temp != null) {
+ System.out.print(temp.data +" ");
+ temp = temp.next;
+ }
+ }
+
+ public boolean isEmpty() {
+ return head == null;
+ }
+
+ public E removeLast() throws Exception {
+ Node temp = head;
+
+ if(temp == null) {
+ throw new Exception("Cannot remove last element from empty linked list");
+ }
+
+ if(temp.next == null) {
+>>>>>>> 24de017... Initial commit
Node toRemove = head;
head = null;
return toRemove.data;
}
+<<<<<<< HEAD
while (temp.next.next != null) {
+=======
+
+ while(temp.next.next != null) {
+>>>>>>> 24de017... Initial commit
temp = temp.next;
}
Node toRemove = temp.next;
temp.next = null;
return toRemove.data;
}
+<<<<<<< HEAD
public E getLast() throws Exception {
Node temp = head;
@@ -59,15 +103,33 @@ public E getLast() throws Exception {
throw new Exception("Cannot peek last element from empty linked list");
}
while (temp.next != null) {
+=======
+
+ public E getLast() throws Exception {
+ Node temp = head;
+
+ if(temp == null) {
+ throw new Exception("Cannot peek last element from empty linked list");
+ }
+ while(temp.next != null) {
+>>>>>>> 24de017... Initial commit
temp = temp.next;
}
return temp.data;
}
+<<<<<<< HEAD
public static class Node {
public E data;
public Node next;
+=======
+
+ public static class Node {
+ public E data;
+ public Node next;
+
+>>>>>>> 24de017... Initial commit
public Node(E data) {
this.data = data;
next = null;
diff --git a/lists/MyArrayList.java b/lists/MyArrayList.java
index 2c6faef..ad766c3 100644
--- a/lists/MyArrayList.java
+++ b/lists/MyArrayList.java
@@ -9,6 +9,7 @@ public class MyArrayList {
public static void main(String[] args) {
List fruits = new LinkedList();
+<<<<<<< HEAD
fruits.add("Apple");
fruits.add("Orange");
@@ -19,6 +20,18 @@ public static void main(String[] args) {
fruits.toArray(temp);
for (String e : temp) {
+=======
+
+ fruits.add("Apple");
+ fruits.add("Orange");
+ fruits.add("Hi");
+
+ String temp[] = new String[fruits.size()];
+
+ fruits.toArray(temp);
+
+ for(String e: temp) {
+>>>>>>> 24de017... Initial commit
System.out.println(e);
}
}
diff --git a/lists/Pair.java b/lists/Pair.java
index 4f34954..0741db8 100644
--- a/lists/Pair.java
+++ b/lists/Pair.java
@@ -4,14 +4,26 @@ public class Pair {
X x;
Y y;
+<<<<<<< HEAD
+=======
+
+>>>>>>> 24de017... Initial commit
public Pair(X x, Y y) {
this.x = x;
this.y = y;
}
+<<<<<<< HEAD
public void getDescription() {
System.out.println(x + " and " + y);
}
+=======
+
+ public void getDescription() {
+ System.out.println(x +" and " + y);
+ }
+
+>>>>>>> 24de017... Initial commit
}
diff --git a/priorityQueues/MainClass.java b/priorityQueues/MainClass.java
index b4cf4ca..2bbff66 100644
--- a/priorityQueues/MainClass.java
+++ b/priorityQueues/MainClass.java
@@ -5,21 +5,37 @@
public class MainClass {
public static void main(String[] args) {
+<<<<<<< HEAD
PriorityQueue pq = new PriorityQueue<>();
+=======
+
+ PriorityQueue pq = new PriorityQueue<>();
+
+>>>>>>> 24de017... Initial commit
pq.add(45);
pq.add(12);
pq.add(1);
pq.add(100);
+<<<<<<< HEAD
System.out.println(pq);
+=======
+
+ System.out.println(pq);
+
+>>>>>>> 24de017... Initial commit
System.out.println(pq.remove());
System.out.println(pq.remove());
System.out.println(pq.remove());
System.out.println(pq.remove());
+<<<<<<< HEAD
+=======
+
+>>>>>>> 24de017... Initial commit
}
}
diff --git a/queue/MainClass.java b/queue/MainClass.java
index ff313eb..d44e45b 100644
--- a/queue/MainClass.java
+++ b/queue/MainClass.java
@@ -5,21 +5,46 @@ public class MainClass {
public static void main(String[] args) {
MyQueue mq = new MyQueue<>();
-
+<<<<<<< HEAD
+<<<<<<< HEAD
+
+=======
+
+>>>>>>> 24de017... Initial commit
+=======
+ //adding of elements to queue
+>>>>>>> adc9847... Modified main class of queue
mq.enqueue(12);
mq.enqueue(2);
mq.enqueue(123);
mq.enqueue(45);
-
+<<<<<<< HEAD
+<<<<<<< HEAD
+
+=======
+
+=======
+ mq.enqueue(47);
+>>>>>>> c87fe75... Added one more enqueue
+
+>>>>>>> 24de017... Initial commit
System.out.println(mq.dequeue());
System.out.println(mq.dequeue());
System.out.println(mq.dequeue());
System.out.println(mq.dequeue());
System.out.println(mq.dequeue());
+<<<<<<< HEAD
mq.enqueue(451);
System.out.println(mq.dequeue());
+=======
+
+ mq.enqueue(451);
+ System.out.println(mq.dequeue());
+
+
+>>>>>>> 24de017... Initial commit
}
}
diff --git a/queue/MyQueue.java b/queue/MyQueue.java
index 0740af6..b9c768b 100644
--- a/queue/MyQueue.java
+++ b/queue/MyQueue.java
@@ -3,6 +3,7 @@
import linkedLists.MyLinkedList.Node;
public class MyQueue {
+<<<<<<< HEAD
private Node head, rear;
@@ -35,4 +36,38 @@ public E dequeue() {
return temp.data;
}
+=======
+
+ private Node head, rear;
+
+ public void enqueue(E e) {
+
+ Node toAdd = new Node<>(e);
+ if(head == null) {
+ head = rear = toAdd;
+ return;
+ }
+
+ rear.next = toAdd;
+ rear = rear.next;
+
+ }
+
+ public E dequeue() {
+
+ if(head == null) {
+ return null;
+ }
+
+ Node temp = head;
+ head = head.next;
+
+ if(head == null) {
+ rear = null;
+ }
+
+ return temp.data;
+ }
+
+>>>>>>> 24de017... Initial commit
}
diff --git a/sets/MainClass.java b/sets/MainClass.java
index f8f88c0..d693ca8 100644
--- a/sets/MainClass.java
+++ b/sets/MainClass.java
@@ -1,7 +1,10 @@
package sets;
import java.util.*;
+<<<<<<< HEAD
+=======
+>>>>>>> 24de017... Initial commit
public class MainClass {
public static void main(String[] args) {
@@ -10,6 +13,7 @@ public static void main(String[] args) {
x.add(23);
x.add(1);
x.add(6);
+<<<<<<< HEAD
Set y = new HashSet<>();
y.add(1);
@@ -17,6 +21,15 @@ public static void main(String[] args) {
System.out.println(x.containsAll(y));
+=======
+
+ Set y = new HashSet<>();
+ y.add(1);
+ y.add(12);
+
+ System.out.println(x.containsAll(y));
+
+>>>>>>> 24de017... Initial commit
System.out.println(x);
}
}
diff --git a/vectorAndStacks/MainClass.java b/vectorAndStacks/MainClass.java
index 829e9f0..a44c9df 100644
--- a/vectorAndStacks/MainClass.java
+++ b/vectorAndStacks/MainClass.java
@@ -3,6 +3,7 @@
public class MainClass {
public static void main(String[] args) throws Exception {
+<<<<<<< HEAD
MyStack stack = new MyStack<>();
@@ -12,6 +13,17 @@ public static void main(String[] args) throws Exception {
int peeked = stack.peek();
+=======
+
+ MyStack stack = new MyStack<>();
+
+ int popped = stack.pop();
+
+ System.out.println(popped);
+
+ int peeked = stack.peek();
+
+>>>>>>> 24de017... Initial commit
System.out.println(peeked);
}
diff --git a/vectorAndStacks/MyStack.java b/vectorAndStacks/MyStack.java
index 580d69e..3bd1409 100644
--- a/vectorAndStacks/MyStack.java
+++ b/vectorAndStacks/MyStack.java
@@ -3,6 +3,7 @@
import linkedLists.MyLinkedList;
public class MyStack {
+<<<<<<< HEAD
private MyLinkedList ll = new MyLinkedList<>();
@@ -12,16 +13,37 @@ void push(E e) {
E pop() throws Exception {
if (ll.isEmpty()) {
+=======
+
+ private MyLinkedList ll = new MyLinkedList<>();
+
+ void push(E e) {
+ ll.add(e);
+ }
+
+ E pop() throws Exception {
+ if(ll.isEmpty()) {
+>>>>>>> 24de017... Initial commit
throw new Exception("Popping from empty stack is not allowed");
}
return ll.removeLast();
}
+<<<<<<< HEAD
E peek() throws Exception {
if (ll.isEmpty()) {
+=======
+
+ E peek() throws Exception {
+ if(ll.isEmpty()) {
+>>>>>>> 24de017... Initial commit
throw new Exception("Peeking from empty stack is not allowed");
}
return ll.getLast();
}
+<<<<<<< HEAD
+=======
+
+>>>>>>> 24de017... Initial commit
}