Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.46 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace Двусвязный_список
  10. {
  11. class Program
  12. {
  13.  
  14. static int qindex = 0, qnext = 0, qlenght = 0;
  15. static LinkedListOfHouse[] Que = new LinkedListOfHouse[10];
  16.  
  17.  
  18. static void Main(string[] args)
  19. {
  20. Que[0] = new LinkedListOfHouse(); // Создавать в момент клика нового дома
  21. //AddToQue(14, 3, 0);
  22. Que[0].Display();
  23.  
  24. Que[0].AddLast(3, 4);
  25. Que[0].AddLast(2, 2);
  26. Que[0].AddLast(5, 3);
  27. Que[0].remove(3);
  28. Que[0].Display();
  29.  
  30. Console.ReadKey();
  31.  
  32. }
  33.  
  34. // procedure qstore(i:Integer);
  35. // begin
  36. // if (qnext+1)<>qlength then
  37. // begin
  38. // q[qnext]:=i;
  39. // qnext:=qnext+1;
  40. // if qnext=qlength then
  41. // qnext:=0 (* Циклический переход *)
  42. // end
  43. // else
  44. // writeln('Мест нет')
  45. //end;
  46. // Que[0].AddLast(22,33);
  47. // Que[0].AddLast(21, 35);
  48.  
  49. static public void AddToQue(int area, int id, int idex)
  50. {
  51.  
  52. if (qnext + 1 != Que.Length)
  53. {
  54.  
  55. Que[idex].AddLast(area, id);
  56. qnext++;
  57. if (qnext == qlenght) {
  58.  
  59. qnext = 0;
  60. }
  61.  
  62. }
  63. else
  64. {
  65. Console.WriteLine("Net mect");
  66. }
  67.  
  68. }
  69. }
  70.  
  71. //Динамическое кольцо на оснвое массива
  72. //public class CQueue<T>
  73. //{
  74. // private T[] _array;
  75. // private int size;
  76. // private const int defaultCapacity = 10;
  77. // private int capacity;
  78. // private int head;
  79. // private int tail;
  80.  
  81. // public CQueue()
  82. // {
  83. // capacity = defaultCapacity;
  84. // this._array = new T[defaultCapacity];
  85. // this.size = 0;
  86. // this.head = -1;
  87. // this.tail = 0;
  88. // }
  89.  
  90. // public bool isEmpty() //проверка на пустоту
  91. // {
  92. // return size == 0;
  93. // }
  94.  
  95. // public void Enqueue(T newElement)
  96. // {
  97. // if (this.size == this.capacity)
  98. // {
  99. // T[] newQueue = new T[2 * capacity];
  100. // Array.Copy(_array, 0, newQueue, 0, _array.Length);
  101. // _array = newQueue;
  102. // capacity *= 2;
  103. // }
  104. // size++;
  105. // _array[tail++ % capacity] = newElement;
  106. // }
  107.  
  108. // public T Dequeue()
  109. // {
  110. // if (this.size == 0)
  111. // {
  112. // throw new InvalidOperationException();
  113. // }
  114. // size--;
  115. // return _array[++head % capacity];
  116. // }
  117.  
  118.  
  119. // public int Count
  120. // {
  121. // get
  122. // {
  123. // return this.size;
  124. // }
  125. // }
  126. //}
  127.  
  128. class LinkedListOfHouse
  129. {
  130. private Apartaments Head;
  131. //private Apartaments Current;
  132. // private Apartaments Last;
  133. private uint size;
  134.  
  135. public LinkedListOfHouse()
  136. {
  137. size = 0;
  138. Head = null;
  139.  
  140. }
  141.  
  142.  
  143. public bool isEmpty //проверка на пустоту
  144. {
  145. get
  146. {
  147. return size == 0;
  148. }
  149. }
  150.  
  151.  
  152.  
  153. public void AddHead(int newElement, int newElement1 )
  154. {
  155. Head = new Apartaments(newElement, newElement1);
  156.  
  157. //Apartaments newApartaments = new Apartaments(newElement, newElement1);
  158. //if (Head == null)
  159. //{
  160. // // Head = Last = newApartaments;
  161. // Head = newApartaments;
  162. //}
  163. //else
  164. //{
  165. // newApartaments.Next = Head;
  166. // Head = newApartaments; //Head и newApartaments указывают на один и тот же объект
  167. // newApartaments.Next.Prev = Head;
  168. //}
  169. //Count++;
  170. } // Добавить в начало
  171.  
  172. public Apartaments DeleteHead()
  173. {
  174. if (Head == null)
  175. {
  176. throw new InvalidOperationException();
  177. }
  178. else
  179. {
  180. Apartaments temp = Head;
  181. if (Head.Next != null)
  182. {
  183. Head.Next.Prev = null;
  184. }
  185. Head = Head.Next;
  186. Count--;
  187. return temp;
  188. }
  189. } // Удалить с первый элемент
  190.  
  191. public void AddLast(int newElement,int newElement1) {
  192. //{
  193. // Apartaments newApartaments = new Apartaments(newElement, newElement1);
  194.  
  195. // if (Head == null)
  196. // {
  197. // // Head = Last = newApartaments;
  198. // Head = newApartaments;
  199. // newApartaments.Prev = Head;
  200. // Head.Prev = newApartaments;
  201. // }
  202. if (Head == null) AddHead(newElement, newElement1);
  203. else
  204. {
  205. if (Head != null)
  206. {
  207. Apartaments tmp = Head;
  208. while (tmp.Next != null) tmp = tmp.Next;
  209.  
  210. tmp.Next = new Apartaments(newElement, newElement1);
  211. }
  212.  
  213. // Last.Next = newApartaments;
  214. // newApartaments.Prev = Last;
  215. // Last = newApartaments;
  216. }
  217. Count++;
  218. } // Добавить в конец
  219.  
  220. public Apartaments DeleteLast()
  221. {
  222. if (Head.Prev.Prev == null)
  223. {
  224. throw new InvalidOperationException();
  225. }
  226. else
  227. {
  228. Apartaments temp = Head;
  229. if (Head.Prev.Prev != null)
  230. {
  231. Head.Prev.Next = null;
  232. }
  233. Head = Head.Prev.Prev;
  234. Count--;
  235. return temp;
  236. }
  237. } // Удалить элемент с конца
  238.  
  239. public void remove(int key)
  240. {
  241. if (Head == null) throw new InvalidOperationException();
  242.  
  243. if (Head.ApartamentIDGS.Equals(key))
  244. {
  245. Head = Head.Next;
  246. return;
  247. }
  248.  
  249. Apartaments cur = Head;
  250. Apartaments prev = null;
  251.  
  252. while (cur != null && !cur.ApartamentIDGS.Equals(key))
  253. {
  254. prev = cur;
  255. cur = cur.Next;
  256. }
  257.  
  258.  
  259. if (cur == null) Console.WriteLine("cannot delete");
  260.  
  261. //delete cur node
  262. prev.Next = cur.Next;
  263. }
  264.  
  265. public void ClearList() //полностью очистить список
  266. {
  267. while (!isEmpty)
  268. {
  269. DeleteHead();
  270. }
  271. }
  272.  
  273. public uint Count //свойство для size
  274. {
  275. get { return size; }
  276. set { size = value; }
  277. }
  278.  
  279. public void Display() //вывести в прямом порядке
  280. {
  281. if (Head == null)
  282. {
  283. Console.WriteLine("Doubly Linked List is empty");
  284. return;
  285. }
  286. // Current = Head;
  287. // uint count = 1;
  288. //while (Current != null)
  289. //{
  290. // Console.WriteLine("Element " + count.ToString() + " : AREA =" + Current.AreaGS.ToString() + " ID = " + Current.ApartamentIDGS.ToString());
  291. // count++;
  292. // Current = Current.Next;
  293. //}
  294. while (Head != null)
  295. {
  296. Console.WriteLine(" : AREA =" + Head.AreaGS.ToString() + " ID = " + Head.ApartamentIDGS.ToString());
  297. Head = Head.Next;
  298. }
  299.  
  300. }
  301.  
  302. //public void ReverseDisplay() //вывести в обратном порядке
  303. //{
  304. // if (Last == null)
  305. // {
  306. // Console.WriteLine("Doubly Linked List is empty");
  307. // return;
  308. // }
  309. // Current = Last;
  310. // uint count = 1;
  311. // while (Current != null)
  312. // {
  313. // Console.WriteLine("Element " + count.ToString() + " : " + Current.Value.ToString());
  314. // count++;
  315. // Current = Current.Prev;
  316. // }
  317. //}
  318.  
  319. //public void DeleteElement(uint index)
  320. //{ //удалить элемент по индексу
  321. // if (index < 1 || index > size)
  322. // {
  323. // throw new InvalidOperationException();
  324. // }
  325. // else if (index == 1)
  326. // {
  327. // DeleteHead();
  328. // }
  329. // else if (index == size)
  330. // {
  331. // DeleteLast();
  332. // }
  333. // else
  334. // {
  335. // uint count = 1;
  336. // Current = Head;
  337. // while (Current != null && count != index)
  338. // {
  339. // Current = Current.Next;
  340. // count++;
  341. // }
  342. // Current.Prev.Next = Current.Next;
  343. // Current.Next.Prev = Current.Prev;
  344. // }
  345. //}
  346.  
  347. //public Apartaments FindApartaments(object Data) //найти Apartaments и вернуть его
  348. //{
  349. // Current = Head;
  350. // while (Current != null)
  351. // {
  352. // Current = Current.Next;
  353. // }
  354. // return Current;
  355. //}
  356.  
  357. //public uint GetIndex(object Data) //достать индекс по значению элемента
  358. //{
  359. // Current = Head;
  360. // uint index = 1;
  361. // while (Current != null)
  362. // {
  363. // Current = Current.Next;
  364. // index++;
  365. // }
  366. // return index;
  367.  
  368. //}
  369.  
  370. }
  371.  
  372. public class Apartaments
  373. {
  374.  
  375. private Apartaments _Next;
  376. private Apartaments _Prev;
  377. private int Area;
  378. private int ApartamentID;
  379.  
  380. public int AreaGS
  381. {
  382. get { return Area; }
  383. set { Area = value; }
  384. }
  385.  
  386. public int ApartamentIDGS
  387. {
  388. get { return ApartamentID; }
  389. set { ApartamentID = value; }
  390. }
  391.  
  392.  
  393. public Apartaments(int Area, int ApartamentID) // Вот тут добавление
  394. {
  395. this.ApartamentID = ApartamentID;
  396. this.Area = Area;
  397. }
  398. public Apartaments Next
  399. {
  400. get { return this._Next; }
  401. set { this._Next = value; }
  402. }
  403. public Apartaments Prev
  404. {
  405. get { return this._Prev; }
  406. set { this._Prev = value; }
  407. }
  408. }
  409.  
  410.  
  411.  
  412. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement