Download A1: Analysis of the Problem
Transcript
Suchana Costa
Calendar Database
//get size
public int size()
{
return size;
}
//print whole calendar (traverses the linked list and prints out the Activity info (date, time, etc) in
each NOde
public void print()
{
for (ActivityNode current = head; current != null; current = current.next)
{
System.out.print(current.myActivity);
}
}
public void selectionSort()
{
ActivityNode minNode;
for (ActivityNode front = head; front != null; front = front.next)
{
minNode = front;
for (ActivityNode current = front; current !=null; current = current.next)
{
//Compare months to see which is the earlier occurying month
if ((minNode.myActivity.getMonth()<(current.myActivity.getMonth())))
{
//Compare dates to find the earlier occuring date
if(minNode.myActivity.getDate() <
current.myActivity.getDate())
{
minNode = current;
}
}
}
}
//swap
Activity temp = front.myActivity;
front.myActivity = minNode.myActivity;
minNode.myActivity = temp;
}
//to file
public void save(String filename)
{
//open file using filename
RandomAccessFile file = new RandomAccessFile(filename, "rw");
//write out to file the size
Int saveSize = size;
file.writeUTF(saveSize);
//traverse through LL and writeUTF
for (ActivityNode myNode = Cal.getHead(); myNode != null; myNode = myNode.next)
27