Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e12ef78

Browse files
estudos
1 parent 9fb588b commit e12ef78

File tree

8 files changed

+299
-135
lines changed

8 files changed

+299
-135
lines changed

‎CrackingCodeInterview/.idea/workspace.xml

Lines changed: 155 additions & 134 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎CrackingCodeInterview/raw/heap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
http://algorithms.tutorialhorizon.com/binary-min-max-heap/
2+
https://www.hackerearth.com/practice/data-structures/trees/heapspriority-queues/tutorial/
3+
https://www.cprogramming.com/tutorial/computersciencetheory/heap.html
4+
https://pt.wikipedia.org/wiki/Heap
5+
https://en.wikipedia.org/wiki/Binary_heap
6+
https://www.tutorialspoint.com/data_structures_algorithms/heap_data_structure.htm
7+
8+
Search: heap data structure princeton
9+
http://www.cs.princeton.edu/~wayne/cs423/lectures/heaps-4up.pdf
10+
https://algs4.cs.princeton.edu/24pq/
11+
https://algs4.cs.princeton.edu/24pq/MaxPQ.java.html
12+
13+
https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/BinomialHeaps.pdf
14+
https://algs4.cs.princeton.edu/24pq/MaxPQ.java
15+
https://algs4.cs.princeton.edu/24pq/MinPQ.java.html
16+
https://www.coursera.org/learn/algorithms-part1/lecture/Uzwy6/binary-heaps
17+
https://www.coursera.org/learn/algorithms-part1/lecture/ZjoSM/heapsort

‎CrackingCodeInterview/raw/linkedlist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Floyd Cycle Detection
2+
https://en.wikipedia.org/wiki/Cycle_detection
3+
http://www.geeksforgeeks.org/detect-loop-in-a-linked-list/
4+
http://www.geeksforgeeks.org/detect-and-remove-loop-in-a-linked-list/

‎CrackingCodeInterview/src/datastructure/HeapFindRunningMedian.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
package datastructure;
22

33

4+
import java.io.BufferedReader;
5+
import java.io.InputStreamReader;
6+
import java.io.OutputStreamWriter;
7+
import java.io.PrintWriter;
8+
49
/**
510
* https://www.hackerrank.com/challenges/ctci-find-the-running-median/problem
611
*
712
* */
813
public class HeapFindRunningMedian {
914

15+
public static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
16+
public static final PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out), true);
17+
1018
public static void main(String[] args) {
1119

1220
}

‎CrackingCodeInterview/src/datastructure/LinkedListDetectCycle.java

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,85 @@
33

44
/**
55
* https://www.hackerrank.com/challenges/ctci-linked-list-cycle/problem
6+
* DONE
67
* */
78
public class LinkedListDetectCycle {
89

9-
public static void main(String[] args) {
10+
class Node {
11+
int data;
12+
Node next;
13+
}
14+
15+
private static LinkedListDetectCycle linkedListDetectCycle = new LinkedListDetectCycle();
16+
17+
public Node head, tail;
18+
19+
boolean hasCycle(Node head) {
20+
return s1(head);
21+
}
22+
23+
public boolean s1(Node head) {
24+
Node slow = head, fast = head;
25+
while( slow != null && fast != null && fast.next != null) {
26+
slow = slow.next;
27+
fast = fast.next.next;
28+
if (slow == fast)
29+
return true;
30+
}
31+
return false;
32+
}
33+
34+
public void add(Node node) {
35+
if(head == null) {
36+
tail = node;
37+
tail.data = node.data;
38+
head = tail;
39+
}
40+
else {
41+
Node copy = tail;
42+
tail = node;
43+
tail.data = node.data;
44+
copy.next = tail;
45+
}
46+
}
1047

48+
public void removeAll() {
49+
while (head != null)
50+
head = head.next;
51+
tail = null;
52+
}
53+
54+
55+
public void start() {
56+
57+
Node [] nodesA = {
58+
new Node()
59+
,new Node()
60+
,new Node()
61+
};
62+
nodesA[0].data = 1;
63+
nodesA[1].data = 2;
64+
nodesA[2].data = 3;
65+
for(Node node : nodesA)
66+
linkedListDetectCycle.add(node);
67+
System.out.println(linkedListDetectCycle.hasCycle(head));
68+
removeAll();
69+
70+
Node [] nodesB = new Node[3];
71+
nodesB[0] = new Node();
72+
nodesB[0].data = 1;
73+
nodesB[1] = new Node();
74+
nodesB[1].data = 2;
75+
nodesB[2] = nodesB[0];
76+
77+
for(Node node : nodesB)
78+
linkedListDetectCycle.add(node);
79+
System.out.println(linkedListDetectCycle.hasCycle(head));
80+
}
81+
82+
83+
public static void main(String[] args) {
84+
linkedListDetectCycle.start();
1185
}
1286

1387
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package datastructure;
2+
3+
import java.util.Comparator;
4+
5+
public class MinHeap {
6+
7+
public class Data {
8+
public int priority;
9+
public Data(int priority) {
10+
this.priority = priority;
11+
}
12+
@Override
13+
public String toString() {
14+
return String.format("Prioridade %d", priority);
15+
}
16+
}
17+
18+
public class ComparatorPLessThanQ implements Comparator<Data> {
19+
@Override
20+
public int compare(Data p, Data q) {
21+
return p.priority - q.priority;
22+
}
23+
}
24+
25+
public boolean less(Data p, Data q) {
26+
return p.priority - q.priority < 0;
27+
}
28+
29+
public Data [] arrayData;
30+
public int size, position;
31+
32+
public void maxHeapifY(Data newData) {
33+
34+
}
35+
36+
37+
public static void main(String[] args) {
38+
39+
}
40+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /