Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Data is stored in a wrong way in linkedlist-Help (http://www.go4expert.com/forums/data-stored-wrong-linkedlist-help-t3951/)

shah123 20Apr2007 13:49

Data is stored in a wrong way in linkedlist-Help
 
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 20Apr2007 15:20

Re: Data is stored in a wrong way in linkedlist-Help
 
Probably because of
Code:

insertAt(str, ind);


All times are GMT +5.5. The time now is 01:43.