Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Loop in Linked List #41

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f11bbe0
Update MainLinkedList.java
Mukulbaid63 May 31, 2020
8bf083a
Update MyLinkedList.java
Mukulbaid63 May 31, 2020
ee772b4
Update MainClass.java
Mukulbaid63 Jun 1, 2020
6e9c44d
Update MyStack.java
Mukulbaid63 Jun 1, 2020
fe2ae06
Updated Comments
Mukulbaid63 Jun 1, 2020
be81fbd
Update MyStack.java
Mukulbaid63 Jun 1, 2020
b7c435f
Update MainClass.java
Mukulbaid63 Jun 1, 2020
6c3825c
Update README.md
Mukulbaid63 Jun 1, 2020
a24e23e
Update SubarrayWithZeroSum.java
Mukulbaid63 Jun 2, 2020
c18cead
Update README.md
Mukulbaid63 Jun 3, 2020
1aae50d
Update README.md
Mukulbaid63 Jun 5, 2020
0b5a250
Merge branch 'master' into master
Mukulbaid63 Jun 5, 2020
d356291
Update README.md
Mukulbaid63 Jun 5, 2020
25ce66a
Update MainClass.java
Mukulbaid63 Jun 5, 2020
0a699d2
Merge pull request #6 from Mukulbaid63/Mukulbaid63-patch-5
Mukulbaid63 Jun 5, 2020
59d07c2
Update MainClass.java
Mukulbaid63 Jun 6, 2020
b6a6c52
Update MainClass.java
Mukulbaid63 Jun 6, 2020
da871e7
Update MyArrayList.java
Mukulbaid63 Jun 7, 2020
fc6953c
Added Github video link
Mukulbaid63 Jun 8, 2020
d63b761
Update README.md
Mukulbaid63 Jun 8, 2020
332024c
Merge branch 'master' into master
Mukulbaid63 Jun 8, 2020
04b6cf3
Detect Loop in Linked List
Mukulbaid63 Sep 30, 2020
5a3809f
Create DetectLoop1.java
Mukulbaid63 Sep 30, 2020
ee775fb
Merge pull request #9 from Mukulbaid63/Mukulbaid63-patch-8
Mukulbaid63 Sep 30, 2020
a15b860
Create HeightCheckerLeetcode.java
Mukulbaid63 Sep 30, 2020
c67cef7
Merge pull request #10 from Mukulbaid63/Mukulbaid63-patch-9
Mukulbaid63 Sep 30, 2020
0009411
Added new Java 8 features important for placements
Oct 17, 2020
4f21bf5
Merge pull request #11 from namankhurpia/add_java_8_features
Mukulbaid63 Oct 27, 2020
e5657bb
Merge pull request #8 from Mukulbaid63/Mukulbaid63-patch-7
Mukulbaid63 Oct 27, 2020
6d0476a
Merge pull request #5 from Mukulbaid63/Mukulbaid63-patch-4
Mukulbaid63 Oct 27, 2020
1b3a7ef
Update README.md
Mukulbaid63 Oct 27, 2020
c3e2bcd
Update README.md
Mukulbaid63 Oct 27, 2020
7a723d0
Merge pull request #12 from Mukulbaid63/Mukulbaid63-patch-10
Mukulbaid63 Oct 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into master
  • Loading branch information
Mukulbaid63 authored Jun 5, 2020
commit 0b5a2500c33baecf831a95d54e74059c973070c1
5 changes: 3 additions & 2 deletions interviewQuestions/SubarrayWithZeroSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public static void main(String[] args) {
for (int element : a) {
set.add(sum);
sum += element;
if(set.contains(sum-k)) {//Zero sum will only exist if the cumulative sum of the elements excluding the current element
//and after including the current element are equal
//Zero sum will only exist if the cumulative sum of the elements excluding the current element
//and after including the current element are equal
if (set.contains(sum - k)) {
found = true;
break;
}
Expand Down
13 changes: 8 additions & 5 deletions linkedLists/MainLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ public class MainLinkedList {
public static void main(String[] args) {

MyLinkedList<String> myLL = new MyLinkedList();

for(int i = 0; i<10; i++) {
myLL.add(i+"added"); // add method use to add a element in the last node of the linked list
}


for (int i = 0; i < 10; i++) {
// add method use to add a element in the last node of the linked list
myLL.add(i + "added");

}
// print method use to print the linked list
myLL.print();
}

}

24 changes: 16 additions & 8 deletions linkedLists/MyLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

public class MyLinkedList<E> {

Node<E> head; //E is the Class defining the type of the inputs accepted


//E is the Class defining the type of the inputs accepted
Node<E> head;

public void add(E data) {
Node<E> toAdd = new Node<E>(data);

if (isEmpty()) {
head = toAdd;
return;
}

Node<E> temp = head;//initialising temp as head to traverse the Linked list without breaking the chain
while(temp.next != null) {// control from loop exits as soon as next element becomes null

//initialising temp as head to traverse the Linked list without breaking the chain
Node<E> temp = head;
// control from loop exits as soon as next element becomes null
while (temp.next != null) {

temp = temp.next;
}
temp.next = toAdd;// adding the new node after reacing to the end of linked list
// adding the new node after reaching to the end of linked list
temp.next = toAdd;
}

void print() {
Expand Down Expand Up @@ -67,8 +73,10 @@ public E getLast() throws Exception {
public static class Node<E> {
public E data;
public Node<E> next;

public Node(E data) { //constructor

//constructor
public Node(E data) {

this.data = data;
next = null;
}
Expand Down
18 changes: 12 additions & 6 deletions vectorAndStacks/MainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ public class MainClass {
public static void main(String[] args) throws Exception {

MyStack<Integer> stack = new MyStack<>();

int popped = stack.pop();// delete the top element of the stack.

System.out.println(popped);//print the last popped element of the stack.

System.out.println(stack.peek());//print the top element of the stack.

// delete the top element of the stack.
int popped = stack.pop();

//print the last popped element of the stack.
System.out.println(popped);

//print the top element of the stack.
int peeked = stack.peek();

System.out.println(peeked);

}

}
8 changes: 6 additions & 2 deletions vectorAndStacks/MyStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ void push(E e) {
}

E pop() throws Exception {
//handling the empty linked list while trying to pop
if(ll.isEmpty()) {
throw new Exception("Popping from empty stack is not allowed");//handling the empty linked list while trying to pop
throw new Exception("Popping from empty stack is not allowed");

}
return ll.removeLast();
}

E peek() throws Exception {
//handling the empty linked list while trying to peek
if(ll.isEmpty()) {
throw new Exception("Peeking from empty stack is not allowed");//handling the empty linked list while trying to peek
throw new Exception("Peeking from empty stack is not allowed");

}
return ll.getLast();
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.