VitalyD

Untitled

May 13th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp14
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             LinkedList list = new LinkedList();
  14.  
  15.             list.Add(105);
  16.             list.Add(10);
  17.             list.Add(5);
  18.             list.Add(4);
  19.  
  20.  
  21.             list.Remove(105);
  22.  
  23.  
  24.             Console.ReadLine();
  25.             //Node current = GetRoot();
  26.  
  27.             //while (current != null)
  28.             //{
  29.             //    Console.WriteLine(current.Data);
  30.             //    current = current.Next;
  31.  
  32.         }
  33.  
  34.         static Node GetRoot()
  35.         {
  36.             return new Node(0,
  37.                 new Node(1,
  38.                 new Node(2,
  39.                 new Node(3,
  40.                 new Node(4,
  41.                 new Node(5, null))))));
  42.         }
  43.  
  44.     }
  45.  
  46.     class LinkedList
  47.     {
  48.         private Node _root;
  49.         public int Count { get; private set; }
  50.  
  51.         public LinkedList()
  52.         {
  53.  
  54.         }
  55.  
  56.         public void Add(int value)
  57.         {
  58.             Node curNode = _root;
  59.  
  60.             if (curNode != null)
  61.             {
  62.                 while (curNode.Next == null)
  63.                 {
  64.                     curNode.Next = new Node(value, null);
  65.                 }
  66.             }
  67.             else
  68.             {
  69.                 _root = new Node(value, null);
  70.             }
  71.  
  72.         }
  73.  
  74.         public void Remove(int value)
  75.         {
  76.             Node ndroot = _root;
  77.             Node prevNode = null;
  78.             while (ndroot.Data == value)
  79.             {
  80.                 if (prevNode == null)
  81.                 {
  82.                     prevNode = ndroot;
  83.                 }
  84.                 else
  85.                 {
  86.                     prevNode = ndroot.Next;
  87.                 }
  88.  
  89.  
  90.                 prevNode = ndroot;  
  91.                 ndroot = ndroot.Next;
  92.             }
  93.         }
  94.  
  95.         public void RemoveAt(int index)
  96.         {
  97.             Node nodet = _root;
  98.  
  99.             if (index == 0)
  100.             {
  101.  
  102.             }
  103.         }
  104.  
  105.         public void Reverse()
  106.         {
  107.  
  108.         }
  109.  
  110.         public bool Contains(int value)
  111.         {
  112.             throw new NotImplementedException();
  113.         }
  114.     }
  115.  
  116.     class Node
  117.     {
  118.         public Node Next;
  119.         public int Data;
  120.  
  121.         public Node(int data, Node next)
  122.         {
  123.             Next = next;
  124.             Data = data;
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment