Reader Level:

Insertion at the begining of a Linklist in C#

By Abhishek Bhandari on Jul 11, 2009
This code snippet shows how to insert data to a Linklist at the beginning.

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

namespace ConsoleApplication38
    class node
        public int delete;
        public int data;/*it will store the data*/
        public node link;/*it will hold the address of the next memory location where the data is stored*/
    class Program
        /*these are the variables */
        public static node START;
        public static node LASt;
        public static node CURRENT;
        public Program()
            START = null;
            LASt = null;
        public void insertionbegin()
            node newnode = new node();
            Console.WriteLine("Enter the data");
   = int.Parse(Console.ReadLine());
   = START;
            START = newnode;
            Console.WriteLine("DAta has been inserted");


        public void displaynode()
            Console.WriteLine("Data in the list are");
            CURRENT = START;
            while (CURRENT != null)
                CURRENT =;


        static void Main(string[] args)

            Program obj = new Program();
                Console.WriteLine("**        MAIN MENU     *****************");
                Console.WriteLine("*1.Inserting at the end of the list******");
                Console.WriteLine("*2.Insertion at the begining of the list****");
                Console.WriteLine("*3.Display the list       *******************");
                Console.WriteLine("*4.Exit                      ****************");
                Console.WriteLine("\nEnter ur choice");
                int choice = int.Parse(Console.ReadLine());
                switch (choice)
                    case 1: { break; }
                    case 2: { obj.insertionbegin(); break; }
                    case 3: { obj.displaynode(); break; }
                    case 4: { break; }
                    default: { Console.WriteLine("Invalid option"); break; }
            } while (true);


Abhishek Bhandari
Abhishek Bhandari

well right im learning data structures n soon ill be learning xml so ill share all the imformation that i will learn hope u may find your answers in my sharing till then enjoy \m/\m/