SIGN UP MEMBER LOGIN:    
ARTICLE

Insertion at the begining of a Linklist in C#

Posted by Abhishek Bhandari Articles | C# Language July 11, 2009
This code snippet shows how to insert data to a Linklist at the beginning.
Reader Level:

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");
            newnode.data = int.Parse(Console.ReadLine());
            newnode.link = START;
            START = newnode;
            Console.WriteLine("DAta has been inserted");

        }

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

        }

        static void Main(string[] args)

        {
            Program obj = new Program();
            do
            {
                Console.Clear();
                Console.WriteLine("********************************************");
                Console.WriteLine("**        MAIN MENU     *****************");
                Console.WriteLine("**************************************");
                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("*********************************************");
                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);
            Console.ReadLine();

        }
    }
}

Login to add your contents and source code to this article
share this article :
post comment
 

ok as u say sir ill try my level best well im new to these thing ..sir i wana be what u are ok so to achieve my dream im working ok ok but after understanding and practising these logics i froget them after 3 to 4 days i dont know why or these weak points are telling me that software is not my line ..hummm im confused but still hope to understand programming in 5 yrs cauze after 5 yrs  ill be 24 yr old so its time to earn not to learn .
Good Nite
your well wisher
Gniitian Abhishek Bhandari

Posted by Abhishek Bhandari Jul 14, 2009

Hi, Congrats for your first article. 


But , I am sorry to say that this article is not up to par. Only posting code is not going to help any way. If possible, please provide  us some explanation also such that we could get more frit out of your article. 

Thanks 

Posted by Dhananjay Kumar Jul 13, 2009
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor