Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
// partition2.java | |
// demonstrates partitioning an array | |
// uses highest-index (right) element as pivot | |
// to run this program: C>java PartitionApp | |
//////////////////////////////////////////////////////////////// | |
class ArrayPar | |
{ | |
private long[] theArray; // ref to array theArray | |
private int nElems; // number of data items | |
//-------------------------------------------------------------- |
<p>There are three threading problems listed <a href="http://www.d.umn.edu/~cprince/courses/cs5631spring10/lectures/ThreadAndSynch.pdf">here</a>. Do all three of them (separately).</p> | |
<p>This will be due by next Wednesday, Dec. 14th. But, I want you to show me the running code instead of submitting it. Let me know before Monday when you can see me next week.</p> |
- (BOOL) createRelationshipsForDestinationInstance:(NSManagedObject *) destinationAttendance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error { | |
NSArray *sourceAttendances = [manager sourceInstancesForEntityMappingNamed:[mapping name] | |
destinationInstances:[NSArray arrayWithObject:destinationAttendance]]; | |
NSManagedObject *sourceAttendance = [sourceAttendances objectAtIndex:0]; | |
NSArray *allStudents = [[[sourceAttendance valueForKey:@"theSchedule"] valueForKey:@"theCourse"] valueForKey:@"students"]; | |
NSArray *presentStudents = [sourceAttendance valueForKey:@"students"]; | |
NSLog(@"For attendance on %@", [sourceAttendance valueForKey:@"date"]); | |
totalInversions = 0 | |
countInversions (array, start, end) | |
if (start < end) | |
int mid = (start + end)/2 | |
countInversions(array, start, mid) | |
countInversion(array, mid+1, end) | |
merge(array, start, mid, end) | |
// else do nothing | |
#import <Foundation/Foundation.h> | |
@interface MyClass : NSObject | |
@end | |
@implementation MyClass | |
static NSMutableArray *instances; |
import java.util.Random; | |
public class ThreadingThings implements Runnable{ | |
int myID; | |
Random gen; | |
public ThreadingThings(int anID) { | |
myID = anID; | |
gen = new Random(); |
import java.util.Random; | |
class Runner implements Runnable { | |
public void run() { | |
int c = 0; | |
while (c++ < 10000) | |
if (c % 100 == 0) | |
System.out.println("still at " + c); | |
} | |
} |
import java.util.Random; | |
class Counter { | |
private int c=0; | |
public synchronized void increment() { | |
c++; | |
} | |
public synchronized void decrement() { | |
c--; |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
// | |
// PersistenceStack.swift | |
import CoreData | |
public class PersistenceStack: NSObject { | |
let mainContext: NSManagedObjectContext = { | |
let context = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType) | |
context.undoManager = nil | |
context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy |