Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

link list in c#

using System;

//node structure
class Node {
  public int data;
  public Node next;
};

class LinkedList {
  public Node head;
  //constructor to create an empty LinkedList
  public LinkedList(){
    head = null;
  } 

  //display the content of the list
  public void PrintList() {
    Node temp = new Node();
    temp = this.head;
    if(temp != null) {
      Console.Write("The list contains: ");
      while(temp != null) {
        Console.Write(temp.data + " ");
        temp = temp.next;
      }
      Console.WriteLine();
    } else {
      Console.WriteLine("The list is empty.");
    }
  }     
};

// test the code 
class Implementation { 
  static void Main(string[] args) {
    //create an empty LinkedList
    LinkedList MyList = new LinkedList();

    //Add first node.
    Node first = new Node();
    first.data = 10;
    first.next = null; 
    //linking with head node
    MyList.head = first;

    //Add second node.
    Node second = new Node();
    second.data = 20;
    second.next = null; 
    //linking with first node
    first.next = second;

    //Add third node.
    Node third = new Node();
    third.data = 30;
    third.next = null; 
    //linking with second node
    second.next = third;

    //print the content of list
    MyList.PrintList();     
  }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: raycasting unity 
Csharp :: c# collection of generic classes 
Csharp :: string length f# 
Csharp :: what are delegates and how to use them c# 
Csharp :: inheritance 
Csharp :: how to use var in c# 
Csharp :: Implementing video array in unity 
Csharp :: non null array length 
Csharp :: concurrent post request c# 
Csharp :: cefsharp print 
Csharp :: json serialize object capitalization config 
Csharp :: c# null check 
Csharp :: disable button netbeans 
Csharp :: C# wpf show hidden window 
Csharp :: erewt 
Csharp :: infinit range loop c# 
Csharp :: dapper extension 
Csharp :: how to assign 2d physics material through script 
Csharp :: c# windows forms how to get controls in gropu box 
Csharp :: Handlebars c# datetime now 
Csharp :: how to edit a c# list 
Csharp :: c# bitwise and 
Csharp :: c# iterate and pop all elements in stack 
Csharp :: how to pass value to anothe form c# winform 
Csharp :: unity soundclip mix 
Csharp :: c# ile ürün çekme - htmlagilitypack 
Csharp :: c# task call more web api in parallel 
Csharp :: two lowest positive numbers given an array of minimum 
Csharp :: int to binary string with 4 characters 
Csharp :: Query mongodb collection as dynamic 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =