All pastes #975923 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-04-07 20:56 UTC
rendered paste body
//add a StudentNode
	public void add(String name, double GPA)
	{
		StudentNode ptr;

		//case for an empty tree
		if(isEmpty())
		{
			StudentRecord studentFile = new StudentRecord(name, GPA);
			root = new StudentNode(studentFile, null, null);
			return;
		}

		ptr = root;
		while (true)
		{
			if(name.compareToIgnoreCase(ptr.studentFile.name) < 0)
			{
				//goes on left side
				if (ptr.lchild == null)
				{
					ptr.lchild = new StudentNode(new StudentRecord(name, GPA), null, null);
					return;
				}
				else
				{
					ptr = ptr.lchild;
				}
			}
			else
			{
				//goes on right side
				if (ptr.rchild == null)
				{
					ptr.rchild = new StudentNode(new StudentRecord(name, GPA), null, null);
					return;
				}
				else
				{
					ptr = ptr.rchild;
				}
			}
		}
	}