Beispiel #1
0
        public string addIndex(int index, int data)
        {
            CustomLinkedListObject temporary = this.head;
            int counter = 0;
            CustomLinkedListObject saved;

            while (true)
            {
                if (temporary.obj != null)
                {
                    if (index - 1 != counter)
                    {
                        temporary = temporary.obj;
                        counter++;
                    }
                    else
                    {
                        saved         = temporary;
                        temporary.obj = new CustomLinkedListObject(data, saved.obj);
                        this.current  = temporary.obj;
                        break;
                    }
                }
                else
                {
                    return("Fail");
                }
            }
            CustomLinkedListObject.size++;
            return("Success");
        }
Beispiel #2
0
        public string deleteIndex(int index)
        {
            CustomLinkedListObject temporary = this.head;
            int counter = 0;

            while (true)
            {
                if (temporary.obj != null)
                {
                    if (index - 1 != counter)
                    {
                        temporary = temporary.obj;
                        counter++;
                    }
                    else
                    {
                        temporary.obj = temporary.obj.obj;
                        break;
                    }
                }
                else
                {
                    return("Fail");
                }
            }
            CustomLinkedListObject.size--;
            return("Success");
        }
Beispiel #3
0
        public string getIndex(int index)
        {
            CustomLinkedListObject temporary = this.head;
            int counter = 0;

            while (true)
            {
                if (temporary.obj != null)
                {
                    if (index - 1 != counter)
                    {
                        temporary = temporary.obj;
                        counter++;
                    }
                    else
                    {
                        Console.WriteLine(temporary.obj.data);
                        break;
                    }
                }
                else
                {
                    return("Fail");
                }
            }
            return("Success");
        }
Beispiel #4
0
        public void show()
        {
            CustomLinkedListObject temporary = this.head;

            while (temporary.obj != null)
            {
                Console.WriteLine(temporary.data);
                temporary = temporary.obj;
            }
            Console.WriteLine(temporary.data);
        }
Beispiel #5
0
        public string addLast(int data)
        {
            CustomLinkedListObject temporary = this.head;

            while (temporary.obj != null)
            {
                temporary = temporary.obj;
            }
            temporary.obj = new CustomLinkedListObject(data, null);
            CustomLinkedListObject.size += 1;
            this.current = temporary.obj;
            return("Success");
        }
Beispiel #6
0
        public bool Contains(CustomLinkedListObject item)
        {
            CustomLinkedListObject temporary = this.head;
            int counter = 0;

            while (true)
            {
                if (temporary.obj != null)
                {
                    if (temporary.data == item.data)
                    {
                        return(true);
                    }
                    else
                    {
                        temporary = temporary.obj;
                        counter++;
                    }
                }
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            bool       created = false;
            LinkedList newlist;

            Console.WriteLine("Welcome! In the information below you can see the commands for manipulating the data of the linked list.");
            Console.WriteLine("Type Create in order to create your first Linked List.");
            Console.WriteLine("Type Add Last/Add At Index in order to add a new integer in list.");
            Console.WriteLine("Type Delete At Index/Get At Index in order to delete/get an integer from list.");


            while (true)
            {
                LinkedList newlist2 = new LinkedList(new CustomLinkedListObject(10, null));
                newlist2.addLast(2);
                newlist2.addLast(22);
                newlist2.addLast(222);
                newlist2.addLast(2222);
                newlist2.addLast(22222);
                newlist2.getSize();
                Console.WriteLine("For each:");
                foreach (CustomLinkedListObject c in newlist2) // Implented using IEnumerable & IEnumerator
                {
                    Console.WriteLine(c.data + " Worked For Each ");
                }
                CustomLinkedListObject test = new CustomLinkedListObject(222, null);

                string input = Console.ReadLine();
                if (input.Equals("Create") && created == false)
                {
                    created = true;
                    Console.WriteLine("Enter the first number:");
                    string data0 = Console.ReadLine();
                    newlist = new LinkedList(new CustomLinkedListObject(int.Parse(data0), null));
                    while (true)
                    {
                        string input2 = Console.ReadLine();
                        if (input2.Equals("Add Last"))
                        {
                            Console.WriteLine("Enter integer:");
                            string data = Console.ReadLine();
                            newlist.addLast(int.Parse(data));
                        }
                        if (input2.Equals("Add At Index"))
                        {
                            Console.WriteLine("Enter index:");
                            string index = Console.ReadLine();
                            Console.WriteLine("Enter integer:");
                            string data = Console.ReadLine();
                            newlist.addIndex(int.Parse(index), int.Parse(data));
                        }
                        if (input2.Equals("Delete At Index"))
                        {
                            Console.WriteLine("Enter index:");
                            string index = Console.ReadLine();
                            newlist.deleteIndex(int.Parse(index));
                        }
                        if (input2.Equals("Get At Index"))
                        {
                            Console.WriteLine("Enter index:");
                            string index = Console.ReadLine();
                            newlist.getIndex(int.Parse(index));
                        }
                        if (input2.Equals("Show List"))
                        {
                            newlist.show();
                        }
                    }
                }
            }
        }
Beispiel #8
0
 public CustomLinkedListObject(int data, CustomLinkedListObject obj)
 {
     this.data = data;
     this.obj  = obj;
 }
Beispiel #9
0
 public bool Remove(CustomLinkedListObject item)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
 public void Add(CustomLinkedListObject item)
 {
     throw new NotImplementedException();
 }
Beispiel #11
0
 public LinkedList(CustomLinkedListObject obj)
 {
     this.head = obj;
     CustomLinkedListObject.size += 1;
 }