This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void splay(Entry e){ | |
if(e == null || e == root) | |
return; | |
if(e.parent == root){ | |
if(e == e.parent.right) { | |
zig(e.parent); | |
root = e.parent; | |
return; | |
}else { | |
zag(e.parent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void splay(Entry e){ | |
if(e.parent == null) | |
root = e; | |
if(e == null || e == root) | |
return; | |
if(e.parent == root){ | |
if(e == e.parent.right) { | |
zig(e); | |
root = e.parent; | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public E get(E e) { | |
if(e == null) | |
return null; | |
Entry entry = find(e, root, null); | |
return (entry == null) ? null : entry.element; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected Entry find(E elem, Entry t, Entry lastEntry) { | |
if (t == null) { | |
splay(lastEntry); | |
return null; | |
}else { | |
int jfr = elem.compareTo(t.element); | |
if (jfr < 0) | |
return find(elem, t.left, t); | |
else if (jfr > 0) | |
return find(elem, t.right, t); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void splay(Entry e){ | |
if(e == null || e == root) | |
return; | |
if(e.parent == root){ | |
if(e == e.parent.right) { | |
zig(e.parent); | |
return; | |
}else { | |
zag(e.parent); | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean add(E element) { | |
if (element == null) | |
throw new NullPointerException("Can't insert a null element"); | |
else if(head == null) { | |
head = new Entry(element, null); | |
return true; | |
} | |
Entry cmp = head; | |
//Step until the list ends or we're at our proper position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CASE WHEN (CoursesToTake > 0 | |
OR MathCredits < 20 | |
OR ResearchCredits < 10 | |
OR SeminarCourses < 1) THEN 'No' | |
ELSE 'Yes' END AS "MayGraduate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Add courses */ | |
INSERT INTO COURSES(name, credits) | |
VALUES ('Datastrukturer', 8); | |
INSERT INTO COURSES(name, credits) | |
VALUES ('Databases', 8); | |
INSERT INTO COURSES(name, credits) | |
VALUES ('Ingenjörskompetens', 3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE VIEW PathToGraduation AS | |
WITH TotalCredits AS (SELECT id, SUM(credits) AS totalCredits | |
FROM PASSEDCOURSES | |
GROUP BY id), | |
CoursesToTake AS (SELECT id, COUNT(*) AS CoursesToTake | |
FROM UNREADMANDATORY | |
GROUP BY id), | |
MathCredits AS (SELECT id, SUM(credits) AS MathCredits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH TotalCredits AS (SELECT id, SUM(credits) AS totalCredits | |
FROM PASSEDCOURSES | |
GROUP BY id), | |
CoursesToTake AS (SELECT id, COUNT(*) AS CoursesToTake | |
FROM UNREADMANDATORY | |
GROUP BY id), | |
MathCredits AS (SELECT id, SUM(credits) AS MathCredits | |
FROM (PASSEDCOURSES JOIN HASCLASSIFICATIONS |
OlderNewer