Data is stored in a wrong way in linkedlist-Help

Discussion in 'C#' started by shah123, Apr 20, 2007.

  1. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    public static void Main(String[] args)
            {
                Console.WriteLine("Please Enter the data to be Inserted in the LinkList...");
                link lnk = new link();
                String str = "";
    
                while (true)
                {
                    str = Console.ReadLine();
                    if(str.Equals("e"))
                        break;
                    add(str);
    
                }
    
              Console.WriteLine("Do you want to put the data at some specific position?");
                String myString = Console.ReadLine();
                
                Console.WriteLine("Enter element to put at specified position :");
                String s = Console.ReadLine();
                Int32 ind = Int32.Parse(s);
                insertAt(str, ind);
    
    
    When i try to insert the data at some specific position it inserts the element "e" at some random position and also it puts any required element on that position. e.g.

    Console: Do you want to put the data at some specific position?

    pos: 1

    Console.WriteLine("Enter element to put at specified position :");

    3

    So when it display the list it shows like as :

    3

    5

    6

    7

    e

    1

    8

    Why it is inserting "e" in the middle?

    Please advise. Thanks
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,341
    Likes Received:
    379
    Trophy Points:
    83
    Probably because of
    Code:
    insertAt(str, ind);
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice