Created
April 10, 2017 00:20
-
-
Save rnice01/9fe43b5a9e787bccaba49ada11ade821 to your computer and use it in GitHub Desktop.
LinkedList Implementation created by rnice4christ - https://repl.it/GzxE/74
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace LinkedListImplement | |
{ | |
using System; | |
class Node | |
{ | |
public object Data {set; get;} | |
public Node Next {set; get;} | |
} | |
class LinkedList | |
{ | |
public Node Head; | |
public int Size; | |
public LinkedList(object data) | |
{ | |
Head = new Node(); | |
Head.Data = data; | |
Size = 1; | |
} | |
public void Add(object data) | |
{ | |
var new_node = new Node(); | |
new_node.Data = data; | |
new_node.Next = Head; | |
Head = new_node; | |
Size++; | |
} | |
public void PrintList() | |
{ | |
string list_string = "["; | |
Node curr = Head; | |
while (curr != null) { | |
list_string += curr.Data; | |
list_string += "->"; | |
curr = curr.Next; | |
} | |
list_string += "NULL]"; | |
Console.WriteLine(list_string); | |
} | |
public static void Main(string[] args) | |
{ | |
LinkedList my_list = new LinkedList('a'); | |
my_list.Add('b'); | |
Console.WriteLine(my_list.Size); | |
my_list.PrintList(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment