Hi All,
I am working on linked list application which the structure is as:

public static void Main(String[] args)
        {
            Console.WriteLine("Please Enter the data to be Inserted in the LinkList...");
            Object obj = new Object();
            node n = new node();
            linklistImp llist = new linklistImp();
            ArrayList ast = new ArrayList();
            obj = Console.ReadLine();
            llist.Insert(ast);
            
            
        }
        // to Insert the data
        public void Insert(ArrayList ast)
        {
            // to Check if node is empty
            if (head == null)
            {
                head = new node();
                
            }

This is just some basic structure of Linked List. My question is i want to insert the data on runtime from user entry and store. I am not sure completely what to use in main() to store the elements and how? Can you please help.
Thanks

I changed a code small bit.

while (str != "-1") // When i do that it also display -1 as well also when counting it count -1 as well. How to prevent that?
            {
                str = Console.ReadLine();
                llist.Insert(str);
                //int i = Int32.Parse(str);
            }
                //ast = Int32.Parse(str);
                //llist.Insert(i);
                Console.WriteLine("\n");
                Console.WriteLine("The total number of nodes in list are :" + llist.Count());
                Console.WriteLine("\n");
                Console.WriteLine("The data in nodes are : ");
                llist.display();
                Console.ReadLine();
            
            
        }
        // to Insert the data
        public void Insert(String data)
        {
            // to Check if node is empty
            if (head == null)
            {
                head = new node();
                head.data = data;
            }
            else
            {
                // if node is not null 
                node temp = new node();
                temp.data = data;
                temp.next = head;
                head = temp;
            }
            totalnodes++;
        }

That was the solution. It worked

while (true)
            {
                str = Console.ReadLine();
                //ast.Add(str);
                if (str == "-1")
                    break;
                llist.Insert(str);
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.