Data is stored in a wrong way in linkedlist-Help

shah123's Avatar
Contributor
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
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Probably because of
Code:
insertAt(str, ind);