| | |
Need Quick Help LinkList
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
I am having trouble with printing out the number to the console. Instead of 10 printing out I want 16. How can this be fix.
using System; using System.Collections.Generic; using System.Text; namespace LinkList { class Program { static void Main(string[] args) { List studentRecord = new List(); studentRecord.InsertAtFront(10); studentRecord.InsertAtFront(16); studentRecord.InsertAtBack(32); studentRecord.PrintFromLeftToRight(); } } public class ListNode { private object data; private ListNode next; private ListNode prev; public ListNode(object dataValue, ListNode n, ListNode p) { data = dataValue; next = n; prev = p; } // end constructor public ListNode Next { get { return next; } set { next = value; } } // end property Next public ListNode Prev { get { return prev; } set { next = value; } } // end property Prev public object Data { get { return data; } set { data = value; } } // end property Data } // end class ListNode public class List { private ListNode firstNode; private ListNode lastNode; ListNode temporary; public List() { firstNode = lastNode = null; } // end constructor List public ListNode FirstNode { get { return firstNode; } set { firstNode = value; } } public ListNode LastNode { get { return LastNode; } set { LastNode = value; } } public void InsertAtFront(object insertItem) { if (firstNode == null) // link list is empty firstNode = lastNode = new ListNode(insertItem, null, null); else firstNode = new ListNode(insertItem, firstNode, null); } // end method InsertAtFront public void InsertAtBack(object insertItem) { if (firstNode == null) firstNode = lastNode = new ListNode(insertItem, null, null); else firstNode = new ListNode(insertItem, null, lastNode); } // end method InsertAtBack public void PrintFromLeftToRight() { if (firstNode == null) { Console.WriteLine("Link List is empty."); return; } // end if else { ListNode currentNode = lastNode; Console.WriteLine("{0,4}", currentNode.Data); } // end else } // end method PrintFromLeftToRight } // end class List }
![]() |
Other Threads in the C# Forum
- Previous Thread: 2D graphic
- Next Thread: Opening an existing form
Views: 1191 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast button buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms ftp function gcd gdi+ http httpwebrequest image index input install java label list listbox login mandelbrot math mysql networking operator oracle path photoshop picturebox pixelinversion prime programming radians regex remote remoting resource richtextbox save saving serialization server socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view webbrowser windows winforms wpf xml






