Skip to content

Instantly share code, notes, and snippets.

View m0ar's full-sized avatar

Edvard Hübinette m0ar

View GitHub Profile
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);
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;
public E get(E e) {
if(e == null)
return null;
Entry entry = find(e, root, null);
return (entry == null) ? null : entry.element;
}
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);
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;
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
CASE WHEN (CoursesToTake > 0
OR MathCredits < 20
OR ResearchCredits < 10
OR SeminarCourses < 1) THEN 'No'
ELSE 'Yes' END AS "MayGraduate"
/* 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);
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
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