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.Collections;
- namespace ConsoleApplication11
- {
- class intList : System.Collections.ICollection
- {
- int[] M;
- int count;
- const int defaultCapacity = 0;
- public intList(int cap)
- {
- M = new int[cap];
- count = 0;
- }
- // int System.Collections.ICollection.Count
- //{
- // get
- // {
- // return count;
- // }
- //}
- public int Count
- {
- get { return count; }
- set { value = count; }
- }
- public int this[int ind]
- {
- get { return M[ind]; }
- set { value = M[ind]; }
- }
- bool System.Collections.ICollection.IsSynchronized
- {
- get
- {
- return false;
- }
- }
- object System.Collections.ICollection.SyncRoot
- {
- get
- {
- return this;
- }
- }
- void System.Collections.ICollection.CopyTo(Array array, int index)
- {
- intList l = new intList(array.Length);
- foreach(int i in M)
- {
- array.SetValue(i, index);
- index++;
- }
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- for (int i = 0; i < count; i++)
- yield return M[i];
- }
- public int Capacity
- {
- get { return M.Length; }
- set
- {
- if (value < count)
- value = count;
- if (value != M.Length)
- {
- int[] nm = new int[value];
- Array.Copy(M, nm, M.Length);
- M = nm;
- }
- }
- }
- public void Add(int item)
- {
- if (Capacity == count)
- Capacity = count * 2;
- M[count] = item;
- count++;
- }
- public void AddRange(System.Collections.ICollection ar)
- {
- intList s = (intList)ar;
- foreach(int item in s)
- {
- this.Add(item);
- }
- }
- public void SetRange(int k, System.Collections.ICollection ar)
- {
- intList s = (intList)ar;
- foreach(int item in s)
- {
- if (k == Capacity)
- Add(item);
- else
- M[k] = item;
- k++;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- intList IL = new intList(10);
- IL.Add(1);
- IL.Add(2);
- IL.Add(3);
- intList IL1 = new intList(10);
- IL1.Add(4);
- IL1.Add(5);
- IL.AddRange(IL1);
- IL.SetRange(0, IL1);
- Console.WriteLine("count = {0}", IL.Count);
- Console.WriteLine("Capacity = {0}", IL.Capacity);
- for (int i =0; i < IL.Count; i++)
- {
- Console.Write("{0,5}", IL[i]);
- }
- Console.WriteLine();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement