Exclusive Clothing Sale On Flipkart

Get up to 50% off on our latest collection.

Shop Now

Part 7- LinkedList Class creation in C# | Linked List Tutorials in C#

 

using System;

using System.Collections.Generic;

using System.Text;


namespace LinkedListTutorial

{

    class LinkedList

    {

        private Node head;

        private int _linkedListSize;


        public LinkedList()

        {

            this.head = null;

            this._linkedListSize = 0;

        }


        public bool IsEmpty 

        {

            get { return this._linkedListSize == 0; }

        

        }


        public int LinkedListSize 

        {

            get { return this._linkedListSize; }

        }

    }

}




Part 6- Implement the Node in Linked List C# | Linked List Tutorials in C#

Node Implementation program in C#

using System;
using System.Collections.Generic;
using System.Text;

namespace LinkedListTutorial
{
   public class Node
    {
        private object data;
        private Node _next;

        public Node(object data, Node next)
        {
            this.data = data;
            this._next = next;
        }

        public object Data
        {
            get { return this.data; }
            
            set { this.data = value; }
        }


        public Node Next
        {
            get { return this._next; }

            set { this._next = value; }
        }
    }
}






Part 4- Type Of Linked List | Linked List Tutorials in C#


Types of Linked List

The types of linked list are mentioned below:

Singly Linked List: Item traversed only in forward direction.

Doubly Linked List: Item traversed in forward and backward directions.

Circular Singly Linked List: Last element contains link to the first element as next.

Singly Linked List:

Singly linked lists contain nodes which have a data part as well as an address part(pointer) i.e. next, which points to the next node in the sequence of nodes.

The operations we can perform on singly linked lists are insertion, deletion and traversal.


Doubly Linked List:

In a doubly linked list, each node contains a data part and two addresses, one for the previous node and one for the next node.


Circular Singly Linked List :

In circular linked list the last node of the list holds the address of the first node hence forming a circular chain.














Part 3- Why we need pointers in Linked List | Linked List Tutorials in C#

 

In case of array, memory is allocated in contiguous manner, hence array elements get stored in consecutive memory locations. So when you have to access any array element, all we have to do is use the array index, for example arr[2] will directly access the 3rd memory location, returning the data stored there.

But in case of linked list, data elements are allocated memory at runtime, hence the memory location can be anywhere. Therefore to be able to access every node of the linked list, address of every node is stored in the previous node, hence forming a link between every node.


We need this additional pointer because without it, the data stored at random memory locations will be lost. We need to store somewhere all the memory locations where elements are getting stored.


Yes, this requires an additional memory space with each node, which means an additional space of O(n) for every n node linked list.






Part 2-Why Linked List/ LinkedList Vs Array | Linked List Tutorials in C#


Array and Linked list both we use to store linear data of same datatype, but array has some limitation 


      Linked List 

  1. The size of the linked list is dynamic.
  2. Ease of insertion or deletion.
  3. Linked List supports Sequential Access, which means to access any element/node in a linked list, we have to sequentially traverse the complete linked list, upto that element.
  4. To access nth element of a linked list, time complexity is O(n).
  5. In a linked list, new elements can be stored anywhere in the memory.
  6. Memory is allocated at runtime, as and when a new node is added. It's also known as Dynamic Memory Allocation.
  7. Linked list can be Linear(Singly) linked list, Doubly linked list or Circular linked list linked list.
  8. Array gets memory allocated in the Stack section.
   Array

  1. The size of the arrays is fixed, so we should have knowledge of array size in advance.
  2. Inserting and deleting data in array is difficult.
  3. Array supports Random Access, which means elements can be accessed directly using their index, like arr[0] for 1st element, arr[6] for 7th element etc.
  4.  accessing elements in an array is fast with a constant time complexity of O(1).
  5. In an array, elements are stored in contiguous memory location or consecutive manner in the memory.
  6. Memory is allocated as soon as the array is declared, at compile time. It's also known as Static Memory Allocation.
  7. Array can be single dimensional, two dimensional or multidimensional.
  8. Whereas, linked list gets memory allocated in Heap section.






Part 1- Introduction to Linked List | Linked List tutorials in C#


 What is Linked List

  • In simple words, a linked list is a collection of nodes where each node is connected to the next node through a pointer. 
  • A linked list is a linear data structure or dynamic data structure which contain nodes and where each node contains 2 items, one is a data field and another is the reference(pointer) to the next element or node in the list.


Link list Basic Operations

Insertion − Adds an element at the beginning of the list.
Deletion − Deletes an element at the beginning of the list.
Display − Displays the complete list.
Search − Searches an element using the given key.
Delete − Deletes an element using the given key.

Advantages of Linked Lists
  • They are a dynamic in nature which allocates the memory when required.
  • Insertion and deletion operations can be easily implemented.
  • Stacks and queues can be easily executed.
  • Linked List reduces the access time.
Disadvantages of Linked Lists

  • The memory is wasted as pointers require extra memory for storage.
  • No element can be accessed randomly; it has to access each node sequentially.
  • Reverse Traversing is difficult in linked list.
Applications of Linked Lists
  • Linked lists are used to implement stacks, queues, graphs, etc.
  • Mostly Linked list we use for Sorting the data.
  • Linked lists let you insert elements at the beginning and end of the list.
  • In Linked Lists we don't need to know the size in advance.

















Trending News and technology

Trending News and technology

Top 10 Sites for Jobs/ Interview Preparation / Tech Skills in demand /Online Education platform / Freelance Sites to Find Work / Resume Maker

Top 10 Sites for Jobs/ Interview Preparation /  Tech Skills in demand /Online Education platform / Freelance Sites to Find Work / Resume Maker
📌Top 10 Sites for Jobs

1. Naukri
2. Indeed
3. LinkedIN
4. Monster
5. JobBait
6. Careercloud
7. Dice
8. CareerBuilder
9. Jibberjobber
10. Glassdoor

📌Top 10 Tech Skills in demand

1. Machine Learning
2. Mobile Development
3. SEO/SEM Marketing
4. Data Visualization
5. Full Stack Web Development
6. UI/UX Design
7. Cyber-security
8. Cloud Computing/AWS
9. Blockchain
10 IOT

📌Top 10 Sites for Online Education

1. Byju’s
2. edX
3. Coursera
4. Udemy
5. iTunesU Free Courses
6. MIT OpenCourseWare
7. Stanford Online
8 Codecademy
9. Open Culture
10. NPTEL

📌Top 10 Freelance Sites to Find Work

1. Fiverr
2. Upwork
3. Toptal
4. Simply Hired
5. PeoplePerHour
6. Crowded
7. The Creative Group
8. Freelancer
9. TaskRabbit
10. Guru

📌Top 10 Sites to review your resume for free

1. Zety Resume Builder
2. Resumonk
3. Resume dot com
4. VisualCV
5. Cvmaker
6. ResumUP
7. Resume Genius
8. Resumebuilder
9. Resume Baking
10. Enhancv

📌Top 10 Sites for Interview Preparation

1. Ambitionbox
2. AceTheInterview
3. Geeksforgeeks
4. Leetcode
5. Gainlo
6. Careercup
7. Codercareer
8. InterviewUp
9. InterviewBest
10. Indiabix

Exclusive Clothing Sale On Flipkart

Get up to 50% off on our latest collection.

Shop Now