public void Add(CustomLinkedList <T> items) { foreach (T item in items) { Add(item); } }
static void Main(string[] args) { //This is the initial peice of data, it creates the class Console.Write("Enter a piece of data >> "); string data = Console.ReadLine(); CustomLinkedList <string> linkedList = new CustomLinkedList <string>(new CustomLinkedNode <string>(data)); //This adds the other 5 inputs to the LinkedList while (linkedList.Count < 6) { Console.Write("Enter a piece of data >> "); data = Console.ReadLine(); linkedList.Add(data); } //Spacing stuff Console.WriteLine(""); Console.WriteLine("Here is your list:"); //This will go through and print the LinkedList for (int i = 0; i < linkedList.Count; i++) { Console.WriteLine(linkedList.GetData(i)); } //Spacing Console.WriteLine(""); Console.WriteLine("These are the indecies that will be removed: -7, 5, 0, and 2"); //Checking to see the error message works try{ linkedList.Remove(-7); }catch (Exception e) { Console.WriteLine(e.Message); } //Removing the head, tail, and then a random one linkedList.Remove(linkedList.Count - 1); linkedList.Remove(0); linkedList.Remove(2); //Spacing Console.WriteLine(""); Console.WriteLine("Here is what is left of the list:"); //Reprinting the list for (int i = 0; i < linkedList.Count; i++) { Console.WriteLine(linkedList.GetData(i)); } Console.ReadLine(); }
public static void Main() { var linkedList = new CustomLinkedList <int>(); linkedList.Add(new ListItem <int>(1)); linkedList.Add(new ListItem <int>(2)); linkedList.Add(new ListItem <int>(3)); Console.WriteLine(linkedList.First.Value); Console.WriteLine(linkedList.First.NextItem.Value); Console.WriteLine(linkedList.Last.Value); }
static void Main(string[] args) { CustomLinkedList <int> list = new CustomLinkedList <int>(); list.AddHead(5); list.AddHead(2); list.AddHead(3); list.AddTail(19); list.AddTail(20); list.AddTail(11); list.ForEach(x => Console.WriteLine(x)); }
/// <summary> /// Removes the node and all nodes after, creating a new linked list /// </summary> /// <param name="node"></param> /// <returns></returns> public CustomLinkedList <T> RemoveRange(Node <T> node) { ValidateNode(node); CustomLinkedList <T> result = new CustomLinkedList <T>(node); if (node == First) { First = null; } else { node.Previous.Next = null; } Last = node.Previous; node.Previous = null; Count -= result.Count; return(result); }
internal LinkedListEnumerator(CustomLinkedList <T> list) { this.list = list; this.node = list.First; this.current = default(T); }
public static void Main() { var customLinkedList = new CustomLinkedList <int>(); }