Skip to content

Instantly share code, notes, and snippets.

View jjlumagbas's full-sized avatar

JJ Lumagbas jjlumagbas

View GitHub Profile
public class HeapSorter {
private int[] items;
private int heapSize;
private final int ROOT = 0;
public HeapSorter(int[] items) {
this.items = items;
this.heapSize = 0;
}
import java.util.LinkedList;
import java.util.List;
public class HashTable<V> {
private int capacity;
private List<V>[] buckets;
public HashTable(int capacity) {
this.capacity = capacity;
import java.util.List;
public class Graph {
public void addNode(String src) {
}
public void addEdge(String src, String dst) {
}
@jjlumagbas
jjlumagbas / 11-exam-3.py
Created December 6, 2016 03:11
Exam solutions
def factorial(n):
"""
Int -> Int
Compute the factorial of n
"""
result = 1
for i in range(1, n + 1):
result = result * i
@jjlumagbas
jjlumagbas / strings.c
Created December 8, 2016 05:50
Strings in C
#include <stdio.h>
int str_len(char str[]) {
int count = 0;
for (int i = 0; str[i] != '\0'; i++) {
count = count + 1;
}
return count;
}
@jjlumagbas
jjlumagbas / lists.c
Created December 12, 2016 06:17
Arrays in C
#include <stdio.h>
int factorial(int n) {
int result = 1;
/* for i in range(1, n + 1): */
for (int i = 1; i < n + 1; i++) {
result = result * i;
}
return result;
}
@jjlumagbas
jjlumagbas / ReadArgs.java
Last active December 12, 2016 23:53
How to read command line arguments
class ReadArgs {
public static void main(String[] args) {
System.out.println(args.length);
if (args.length >= 1) {
System.out.println("Running commands in file: " + args[0]);
} else {
System.out.println("No args provided. Running in interactive mode");
}
}
}
@jjlumagbas
jjlumagbas / interactive-mode.md
Last active December 13, 2016 00:59
MP4 - Command Prompt sample input/output

Edit in interactive mode

Enter command edit

> edit hello.txt<Enter>
|                              # text editor is now open

add some text

  1. Create a folder with your email address as its name, following the folder structure below (Use up.edu.ph emails!)
  2. Zip that folder up: [email protected] (Use zip! Don't use other types of compression. WRONG: [email protected], [email protected])
  3. Submit the zip file

IMPORTANT: I'm using an auto-grader. If you do not follow these instructions precisely then the grader will fail on your code and you'll be given a 0 for this exercise

Folder structure for code + tests submission

  1. Create a folder with your email address as its name, following the folder structure below (Use up.edu.ph emails!)
  2. Zip that folder up: [email protected] (Use zip! Don't use other types of compression. WRONG: [email protected], [email protected])
  3. Submit the zip file

IMPORTANT: I'm using an auto-grader. If you do not follow these instructions precisely then the grader will fail on your code and you'll be given a 0 for this exercise

Folder structure for tests submission (NOTE: different from code + tests folder structure)

[email protected]