Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp14
- {
- class Program
- {
- static void Main(string[] args)
- {
- LinkedList list = new LinkedList();
- list.Add(105);
- list.Add(10);
- list.Add(5);
- list.Add(4);
- list.Remove(105);
- Console.ReadLine();
- //Node current = GetRoot();
- //while (current != null)
- //{
- // Console.WriteLine(current.Data);
- // current = current.Next;
- }
- static Node GetRoot()
- {
- return new Node(0,
- new Node(1,
- new Node(2,
- new Node(3,
- new Node(4,
- new Node(5, null))))));
- }
- }
- class LinkedList
- {
- private Node _root;
- public int Count { get; private set; }
- public LinkedList()
- {
- }
- public void Add(int value)
- {
- Node curNode = _root;
- if (curNode != null)
- {
- while (curNode.Next == null)
- {
- curNode.Next = new Node(value, null);
- }
- }
- else
- {
- _root = new Node(value, null);
- }
- }
- public void Remove(int value)
- {
- Node ndroot = _root;
- Node prevNode = null;
- while (ndroot.Data == value)
- {
- if (prevNode == null)
- {
- prevNode = ndroot;
- }
- else
- {
- prevNode = ndroot.Next;
- }
- prevNode = ndroot;
- ndroot = ndroot.Next;
- }
- }
- public void RemoveAt(int index)
- {
- Node nodet = _root;
- if (index == 0)
- {
- }
- }
- public void Reverse()
- {
- }
- public bool Contains(int value)
- {
- throw new NotImplementedException();
- }
- }
- class Node
- {
- public Node Next;
- public int Data;
- public Node(int data, Node next)
- {
- Next = next;
- Data = data;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment