Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Runtime.Serialization;
- using System.Text;
- namespace CustomArrayList
- {
- class CustomArrayList
- {
- //елементи, брой елементи, капацитет
- private object[] elements;
- private int count;
- private static int CAPACITY = 4;
- public CustomArrayList()
- {
- elements = new object[CAPACITY];
- count = 0;
- }
- public void Add(object item)
- {
- elements[count] = item;
- count++;
- }
- public void Insert(int index, object item)
- {
- elements[index] = item;
- count++;
- }
- public int IndexOf(object item)
- {
- for (int i = 0; i < elements.Length; i++)
- {
- object currentElement = elements[i];
- if (item.Equals(currentElement))
- {
- return i;
- }
- }
- throw new Exception("Element not found");
- }
- public void Clear()
- {
- Array.Clear(elements, 0, elements.Length);
- }
- public bool Contains(object item)
- {
- for (int i = 0; i < elements.Length; i++)
- {
- object currentElement = elements[i];
- if (item.Equals(currentElement))
- {
- return true;
- }
- }
- return false;
- }
- public override string ToString()
- {
- return string.Join(", ", elements) + "\nCount: "+ count;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement