Advertisement
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;
- namespace Kirill3
- {
- class Program
- {
- static void Main()
- {
- LinkedList<int> list = new LinkedList<int>();
- list.AddFirst(1);
- list.AddFirst(2);
- list.AddLast(3);
- foreach (var item in list)
- {
- Console.WriteLine(item);
- }
- LinkedListMine l = new LinkedListMine();
- l.Add(1);
- l.Add(2);
- l.Add(3);
- l.Print();
- }
- class LinkedListMine
- {
- public Node First;
- public void Add(int i)
- {
- if(First == null)
- {
- First = new Node(i);
- return;
- }
- Node prev = First;
- Node current = First.Next;
- while(current != null)
- {
- prev = current;
- current = current.Next;
- }
- current = new Node(i);
- prev.Next = current;
- }
- public void Print()
- {
- Node current = First;
- Console.WriteLine();
- while (current != null)
- {
- Console.Write(current.Value);
- Console.Write(" ");
- current = current.Next;
- }
- Console.WriteLine();
- }
- }
- class Node
- {
- public int Value;
- public Node Next;
- public Node(int value)
- {
- Value = value;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement