This is just the portion of my class where I am having the issue with DeleteLast...
// ==========================
public void DeleteFirst( )
{
if (Length() >= 1){
if (Length() == 1){
first = null;
last = null;
}
else { // Length() > 1
first = first.next;
} // else
} // if then
} // DeleteFirst
// ========================
public void DeleteLast()
{
if (Length() >= 1)
{
if (Length() == 1)
{
first = null;
last = null;
}
else
{ // Length() > 1
last = last.next;
} // else
}//if then
}//DeleteLast
and my Node class
public class Node
{
// ====================
internal int datum;
internal Node next;
// ===================
// =============
// Constructors:
// =============
// ============
// Constructor:
// ==============================
public Node( int nodeElement,
Node n )
{
datum = nodeElement;
next = n;
} // constructor Node
// =====================
} // class Node
// ===============
the MainProgram
class MainProgram
{
// ===============================
static void Main(string[] args)
{
int menuNumber;
int datumValue;
bool goAgain = true;
SinglyLinkedList listA = new SinglyLinkedList("listA");
SinglyLinkedList listB = new SinglyLinkedList("listB");
SinglyLinkedList listC = new SinglyLinkedList("listC");
// ===============
do // User loop
{
UtilityMethods.Menu( out menuNumber );
// =====================
switch ( menuNumber )
{
case 1:
UtilityMethods.CaseBanner("Initialize ListA.");
listA = new SinglyLinkedList("listA");
break;
case 2:
UtilityMethods.CaseBanner("Initialize ListB.");
listB = new SinglyLinkedList("listB");
break;
case 3:
UtilityMethods.CaseBanner("Output ListA.");
listA.Print();
break;
case 4:
UtilityMethods.CaseBanner("Output ListB.");
listB.Print();
break;
case 5:
UtilityMethods.CaseBanner("Output ListC.");
listC.Print();
break;
case 6:
UtilityMethods.CaseBanner("Insert First ListA.");
UtilityMethods.GetInteger( out datumValue );
listA.InsertFirst( datumValue );
break;
case 7:
UtilityMethods.CaseBanner("Delete First ListA.");
listA.DeleteFirst();
break;
case 8:
UtilityMethods.CaseBanner("Insert First ListB.");
UtilityMethods.GetInteger(out datumValue);
listB.InsertFirst( datumValue );
break;
case 9:
UtilityMethods.CaseBanner("Delete First ListB.");
listB.DeleteFirst();
break;
case 10:
UtilityMethods.CaseBanner("Insert Last ListA.");
UtilityMethods.GetInteger( out datumValue );
listA.InsertLast(datumValue);
break;
case 11:
UtilityMethods.CaseBanner("Delete Last ListA.");
listA.DeleteLast();
break;
case 12:
UtilityMethods.CaseBanner("Insert Last ListB.");
UtilityMethods.GetInteger(out datumValue);
listB.InsertLast( datumValue );
break;
case 13:
UtilityMethods.CaseBanner("Delete Last ListB.");
listB.DeleteLast();
break;
case 14:
UtilityMethods.CaseBanner("Deep Copy ListA to ListB.");
listB.DeepCopy(listA);
break;
case 15:
UtilityMethods.CaseBanner("Deep Copy ListB to ListA.");
listA.DeepCopy(listB);
break;
case 16:
UtilityMethods.CaseBanner("ListC = ListA + ListB.");
listC = new SinglyLinkedList("listC");
listC = listA + listB;
break;
case 17:
UtilityMethods.CaseBanner("ListC = ListA - ListB.");
listC = new SinglyLinkedList("listC");
listC = listA - listB;
break;
case 18:
if (listA > listB)
{
Console.WriteLine("ListA is larger than ListB");
}
else if (listA < listB)
{
Console.WriteLine("ListB is larger than ListA");
}
else
{
Console.WriteLine("ListA and ListB must be equal.");
}
break;
case 19:
if (listA == listB)
{
Console.WriteLine("ListA and ListB are equal length.");
}
else
{
Console.WriteLine("ListA and ListB are not equal length.");
}
break;
case 20:
if (listA >= listB)
{
Console.WriteLine("ListA is greater than or equal to ListB.");
}
else if (listA <= listB)
{
Console.WriteLine("ListA is less than or equal to ListB.");
}
else
{
Console.WriteLine("ListA and ListB must be equal.");
}
break;
case 21:
UtilityMethods.CaseBanner("Exit Program.");
goAgain = false;
break;
default:
Console.WriteLine("Invalid menu item.");
break;
} // switch
// ===========
} while ( goAgain );
// ====================
} // method Main
// ================
} // class MainProgram
// ======================
} // namespace SinglyLinkedListProject
Thanks so much for any advice

New Topic/Question
Reply



MultiQuote







|