Advertisement
Ang377ou

conarraylist

Mar 23rd, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. //clsarraylist
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace conArrayList
  8. {
  9. class ArrayList:IList
  10. {
  11. protected int size;
  12. protected int current;
  13. protected int head;
  14. protected int tail;
  15. protected object[] array;
  16. //private object first, last;
  17. private int count;
  18.  
  19. public object Last
  20. {
  21. get
  22. {
  23. try
  24. {
  25. return array[tail-1];
  26. }
  27. catch (IndexOutOfRangeException)
  28. {
  29. Console.WriteLine("List is empty!");
  30. return -32767;
  31. }
  32. }
  33. }
  34.  
  35. public ArrayList(int size)
  36. {
  37. this.size = size;
  38. array = new object[size];
  39. head = -1;
  40. tail = 0;
  41. current = 0;
  42. Count = 0;
  43. }
  44.  
  45. public bool IsEmpty()
  46. {
  47. return(Count==0);
  48. }
  49. public bool IsFull()
  50. {
  51. return (Count == size);
  52. }
  53. public void Clear()
  54. {
  55. this.head = -1;
  56. tail = 0;
  57. current = 0;
  58. this.Count = 0;
  59. GC.Collect();
  60. GC.WaitForPendingFinalizers();
  61. }
  62.  
  63. public void Insert(object item)
  64. {
  65. if (!IsFull())
  66. {
  67. if (head == -1)//empty
  68. {
  69. head=head+1;
  70. array[head] = item;
  71. }
  72. else
  73. {
  74. tail = tail + 1;
  75. array[tail] = item;
  76. }
  77. Count++;
  78. }
  79. else
  80. {
  81. Console.WriteLine("List is full");
  82. }
  83. }
  84.  
  85. public object First
  86. {
  87. get
  88. {
  89. try
  90. {
  91. return array[head];
  92. }
  93. catch (IndexOutOfRangeException)
  94. {
  95. Console.WriteLine("List is empty!");
  96. return -32767;
  97. }
  98. }
  99.  
  100. }
  101.  
  102. public int Count
  103. {
  104. get { return count; }
  105. set { count = value; }
  106. }
  107.  
  108. public void DisplayList()
  109. {
  110. foreach (object val in array)
  111. {
  112. Console.Write(val+" ");
  113. }
  114. }
  115. }
  116. }
  117. //clsilist
  118. using System;
  119. using System.Collections.Generic;
  120. using System.Linq;
  121. using System.Text;
  122.  
  123. namespace conArrayList
  124. {
  125. interface IList
  126. {
  127. int Count
  128. {
  129. set;
  130. get;
  131. }
  132.  
  133. object First
  134. {
  135. get;
  136. }
  137.  
  138. object Last
  139. {
  140. get;
  141. }
  142.  
  143. bool IsEmpty();
  144. void Insert(object item);
  145. void DisplayList();
  146. //bool Find(object item);
  147. //void Remove(object item);
  148. //void InsertAt(object item, int index);
  149. void Clear();
  150. }
  151. }
  152. //nodelist
  153. using System;
  154. using System.Collections.Generic;
  155. using System.Linq;
  156. using System.Text;
  157.  
  158. namespace conArrayList
  159. {
  160. public class Node
  161. {
  162. private object data;
  163. private Node next;
  164.  
  165. public Node(object item, Node n)
  166. {
  167. this.Data= item;
  168. this.Next= n;
  169. }
  170.  
  171. public object Data
  172. {
  173. get { return data; }
  174. set { data = value; }
  175. }
  176.  
  177. internal Node Next
  178. {
  179. get { return next; }
  180. set { next = value; }
  181. }
  182. }
  183. }
  184. //program
  185. using System;
  186. using System.Collections.Generic;
  187. using System.Linq;
  188. using System.Text;
  189.  
  190. namespace conArrayList
  191. {
  192. class Program
  193. {
  194. static void Main(string[] args)
  195. {
  196. ArrayList list = new ArrayList(4);
  197. list.Insert(10);
  198. list.Insert(20);
  199. list.Insert(30);
  200.  
  201. list.DisplayList();
  202. }
  203. }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement