Advertisement
Guest User

adeel

a guest
May 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace WerkCollege5Blocus.Logica
  9. {
  10. public class Vector<T> : IEnumerable<T>
  11. {
  12. private T[] myArray;
  13.  
  14. private int index;
  15.  
  16. public Vector(int capaciteit = 1)
  17. {
  18. myArray = new T[capaciteit];
  19. index = 0;
  20. }
  21.  
  22. public void PushBack(T obj)
  23. {
  24. if (myArray.Length == index)
  25. {
  26. Grow();
  27. }
  28. myArray[index] = obj;
  29. index++;
  30. }
  31.  
  32. private void Grow()
  33. {
  34. Array.Resize(ref myArray, myArray.Length * 2);
  35. }
  36.  
  37. public T getItem(int indexer)
  38. {
  39. return myArray[indexer];
  40. }
  41.  
  42. public void PopBack()
  43. {
  44. myArray[index - 1] = default(T);
  45. index--;
  46. }
  47.  
  48. public IEnumerator<T> GetEnumerator()
  49. {
  50. for (int i = 0; i < index; i++)
  51. {
  52. yield return myArray[i];
  53. }
  54. }
  55.  
  56. IEnumerator IEnumerable.GetEnumerator()
  57. {
  58. throw new NotImplementedException();
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement