Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CustomList
- {
- class Program
- {
- static void Main(string[] args)
- {
- CList u = new CList();
- u.Add("papa");
- u.Add("PAPA");
- u.Add("momo");
- u.Add("MOMO");
- u.Add("LALA");
- u.InsertAfter(1, "GOGOGO");
- Console.WriteLine(u.AllToString());
- u.RemoveAt(1);
- Console.WriteLine(u.AllToString());
- }
- }
- class CList
- {
- private object[] arr = new object[] { };
- public void Add(object element)
- {
- int newLength = arr.Length + 1;
- object[] result = new object[newLength];
- for (int i = 0; i < arr.Length; i++)
- {
- result[i] = arr[i];
- }
- result[newLength - 1] = element;
- arr = result;
- }
- public object GetByIndex(int index)
- {
- return arr[index];
- }
- public void RemoveAt(int index)
- {
- int newLength = arr.Length - 1;
- object[] result = new object[newLength];
- for (int i = index; i < arr.Length-1; i++)
- {
- arr[i] = arr[i + 1];
- }
- arr[arr.Length-1] = null;
- for (int i = 0; i < arr.Length - 1; i++)
- {
- result[i] = arr[i];
- }
- arr = result;
- }
- public string AllToString()
- {
- string result = "";
- for (int i = 0; i < arr.Length; i++)
- {
- result += (arr[i].ToString() + ", ");
- }
- return result;
- }
- public void InsertAfter(int index, object element)
- {
- Add(null);
- for (int i = arr.Length-1; i >= index + 2; i--)
- {
- arr[i] = arr[i - 1];
- }
- arr[index + 1] = element;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement