1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Data is stored in a wrong way in linkedlist-Help

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

  1. shah123

    shah123 New Member

    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

    Probably because of
    Code:
    insertAt(str, ind);
     

Share This Page