Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.48 KB | None | 0 0
  1. #pragma once
  2. #include <stdlib.h>
  3.  
  4. namespace Queue_new {
  5.  
  6. using namespace System;
  7. using namespace System::ComponentModel;
  8. using namespace System::Collections;
  9. using namespace System::Windows::Forms;
  10. using namespace System::Data;
  11. using namespace System::Drawing;
  12.  
  13.  
  14. struct Double_List
  15. {
  16. int Data;
  17. Double_List *Next, *Prior;
  18. };
  19.  
  20. struct Ochered
  21. {
  22. Double_List *Begin;
  23. Double_List *End;
  24. };
  25.  
  26.  
  27. /// <summary>
  28. /// Summary for Form1
  29. ///
  30. /// WARNING: If you change the name of this class, you will need to change the
  31. /// 'Resource File Name' property for the managed resource compiler tool
  32. /// associated with all .resx files this class depends on. Otherwise,
  33. /// the designers will not be able to interact properly with localized
  34. /// resources associated with this form.
  35. /// </summary>
  36. public ref class Form1 : public System::Windows::Forms::Form
  37. {
  38. public:
  39. Form1(void)
  40. {
  41. InitializeComponent();
  42. //
  43. //TODO: Add the constructor code here
  44. //
  45. }
  46.  
  47. protected:
  48. /// <summary>
  49. /// Clean up any resources being used.
  50. /// </summary>
  51. ~Form1()
  52. {
  53. if (components)
  54. {
  55. delete components;
  56. }
  57. }
  58. private: System::Windows::Forms::Label^ label2;
  59. protected:
  60. private: System::Windows::Forms::Label^ label1;
  61. private: System::Windows::Forms::Button^ button2;
  62. private: System::Windows::Forms::TextBox^ textBox3;
  63. private: System::Windows::Forms::TextBox^ textBox2;
  64. private: System::Windows::Forms::TextBox^ textBox1;
  65. private: System::Windows::Forms::Button^ button1;
  66.  
  67. private:
  68. /// <summary>
  69. /// Required designer variable.
  70. /// </summary>
  71. System::ComponentModel::Container ^components;
  72.  
  73. #pragma region Windows Form Designer generated code
  74. /// <summary>
  75. /// Required method for Designer support - do not modify
  76. /// the contents of this method with the code editor.
  77. /// </summary>
  78. void InitializeComponent(void)
  79. {
  80. this->label2 = (gcnew System::Windows::Forms::Label());
  81. this->label1 = (gcnew System::Windows::Forms::Label());
  82. this->button2 = (gcnew System::Windows::Forms::Button());
  83. this->textBox3 = (gcnew System::Windows::Forms::TextBox());
  84. this->textBox2 = (gcnew System::Windows::Forms::TextBox());
  85. this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  86. this->button1 = (gcnew System::Windows::Forms::Button());
  87. this->SuspendLayout();
  88. //
  89. // label2
  90. //
  91. this->label2->AutoSize = true;
  92. this->label2->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
  93. static_cast<System::Byte>(204)));
  94. this->label2->Location = System::Drawing::Point(28, 96);
  95. this->label2->Name = L"label2";
  96. this->label2->Size = System::Drawing::Size(375, 33);
  97. this->label2->TabIndex = 13;
  98. this->label2->Text = L"Количество обрабатываемых цифр";
  99. //
  100. // label1
  101. //
  102. this->label1->AutoSize = true;
  103. this->label1->Font = (gcnew System::Drawing::Font(L"Segoe Script", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
  104. static_cast<System::Byte>(0)));
  105. this->label1->Location = System::Drawing::Point(109, 22);
  106. this->label1->Name = L"label1";
  107. this->label1->Size = System::Drawing::Size(581, 40);
  108. this->label1->TabIndex = 12;
  109. this->label1->Text = L"Удаление из очереди элементов кратные 3";
  110. this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
  111. //
  112. // button2
  113. //
  114. this->button2->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
  115. static_cast<System::Byte>(204)));
  116. this->button2->Location = System::Drawing::Point(223, 209);
  117. this->button2->Name = L"button2";
  118. this->button2->Size = System::Drawing::Size(180, 48);
  119. this->button2->TabIndex = 11;
  120. this->button2->Text = L"Обработать";
  121. this->button2->UseVisualStyleBackColor = true;
  122. this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
  123. //
  124. // textBox3
  125. //
  126. this->textBox3->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  127. static_cast<System::Byte>(204)));
  128. this->textBox3->Location = System::Drawing::Point(420, 214);
  129. this->textBox3->Name = L"textBox3";
  130. this->textBox3->Size = System::Drawing::Size(277, 41);
  131. this->textBox3->TabIndex = 10;
  132. //
  133. // textBox2
  134. //
  135. this->textBox2->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  136. static_cast<System::Byte>(204)));
  137. this->textBox2->Location = System::Drawing::Point(420, 93);
  138. this->textBox2->Name = L"textBox2";
  139. this->textBox2->Size = System::Drawing::Size(79, 41);
  140. this->textBox2->TabIndex = 9;
  141. //
  142. // textBox1
  143. //
  144. this->textBox1->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  145. static_cast<System::Byte>(204)));
  146. this->textBox1->Location = System::Drawing::Point(420, 149);
  147. this->textBox1->Name = L"textBox1";
  148. this->textBox1->Size = System::Drawing::Size(277, 41);
  149. this->textBox1->TabIndex = 8;
  150. //
  151. // button1
  152. //
  153. this->button1->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
  154. static_cast<System::Byte>(204)));
  155. this->button1->Location = System::Drawing::Point(223, 142);
  156. this->button1->Name = L"button1";
  157. this->button1->Size = System::Drawing::Size(180, 48);
  158. this->button1->TabIndex = 7;
  159. this->button1->Text = L"Сгенерировать";
  160. this->button1->UseVisualStyleBackColor = true;
  161. this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
  162. //
  163. // Form1
  164. //
  165. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  166. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  167. this->ClientSize = System::Drawing::Size(756, 293);
  168. this->Controls->Add(this->label2);
  169. this->Controls->Add(this->label1);
  170. this->Controls->Add(this->button2);
  171. this->Controls->Add(this->textBox3);
  172. this->Controls->Add(this->textBox2);
  173. this->Controls->Add(this->textBox1);
  174. this->Controls->Add(this->button1);
  175. this->Name = L"Form1";
  176. this->Text = L"Лабораторная работа 5. Выполнила Моисеенко Валерия К12-2";
  177. this->ResumeLayout(false);
  178. this->PerformLayout();
  179.  
  180. }
  181. #pragma endregion
  182. void Make_Double_List(int n, Double_List** Head, Double_List* Prior)
  183. {
  184. if(n > 0)
  185. {
  186. (*Head) = new Double_List();
  187. (*Head)->Data = rand()%100+0;
  188. (*Head)->Prior = Prior;
  189. (*Head)->Next = NULL;
  190. Make_Double_List(n - 1, &((*Head)->Next), (*Head));
  191. }
  192. else
  193. (*Head) = NULL;
  194. }
  195.  
  196. String^ Print_Double_List(Double_List* Head)
  197. {
  198. String^ result = "";
  199. if(Head != NULL)
  200. result += (Convert::ToString(Head->Data) + " " + Print_Double_List(Head->Next));
  201. else
  202. result = " ";
  203. return result;
  204. }
  205.  
  206. Double_List* Insert_Item_Double_List(Double_List* Head, int Number, int DataItem)
  207. {
  208. Double_List *NewItem = new Double_List;
  209. NewItem->Data = DataItem;
  210. NewItem->Prior = NULL;
  211. NewItem->Next = NULL;
  212. if(Head == NULL)
  213. {
  214. Head = NewItem;
  215. }
  216. else
  217. {
  218. Double_List *Current = Head;
  219. for(int i = 1; i < Number && Current->Next != NULL; i++)
  220. Current = Current->Next;
  221. if(Number == 0)
  222. {
  223. NewItem->Next = Head;
  224. Head->Prior = NewItem;
  225. Head = NewItem;
  226. }
  227. else
  228. {
  229. if(Current->Next != NULL)
  230. Current->Next->Prior = NewItem;
  231. NewItem->Next = Current->Next;
  232. Current->Next = NewItem;
  233. NewItem->Prior = Current;
  234. Current = NewItem;
  235. }
  236. }
  237. return Head;
  238. }
  239.  
  240. Double_List* Delete_Item_Double_List(Double_List* Head, int Number)
  241. {
  242. Double_List *ptr;
  243. Double_List *Current = Head;
  244. for(int i = 1; i < Number && Current != NULL; i++)
  245. Current = Current->Next;
  246. if(Current != NULL)
  247. {
  248. if(Current->Prior == NULL)
  249. {
  250. Head = Head->Next;
  251. delete(Current);
  252. Head->Prior = NULL;
  253. }
  254. else
  255. {
  256. if(Current->Next == NULL)
  257. {
  258. Current->Prior->Next = NULL;
  259. delete(Current);
  260. Current = Head;
  261. }
  262. else
  263. {
  264. ptr = Current->Next;
  265. Current->Prior->Next = Current->Next;
  266. Current->Next->Prior = Current->Prior;
  267. delete(Current);
  268. Current = ptr;
  269. }
  270. }
  271. }
  272. return Head;
  273. }
  274.  
  275. bool Find_Item_Double_List(Double_List* Head, int DataItem)
  276. {
  277. Double_List *ptr;
  278. ptr = Head;
  279. while(ptr != NULL)
  280. {
  281. if(DataItem == ptr->Data)
  282. return true;
  283. else
  284. ptr = ptr->Next;
  285. }
  286. return false;
  287. }
  288.  
  289. bool Empty_Double_List(Double_List* Head)
  290. {
  291. if(Head != NULL)
  292. return false;
  293. else
  294. return true;
  295. }
  296.  
  297. void Delete_Double_List(Double_List* Head)
  298. {
  299. if(Head != NULL)
  300. {
  301. Delete_Double_List(Head->Next);
  302. delete Head;
  303. }
  304. }
  305.  
  306. void Make_Queue(int n, Ochered* End_Queue)
  307. {
  308. Make_Double_List(n, &(End_Queue->Begin), NULL);
  309. Double_List *ptr;
  310. ptr = End_Queue->Begin;
  311. while(ptr->Next != NULL)
  312. ptr = ptr->Next;
  313. End_Queue->End = ptr;
  314. }
  315.  
  316. String^ Print_Queue(Ochered* Begin_Queue)
  317. {
  318. return Print_Double_List(Begin_Queue->Begin);
  319. }
  320.  
  321. void Add_Item_Queue(int NewElem, Ochered* End_Queue)
  322. {
  323. if(End_Queue->Begin == NULL)
  324. {
  325. End_Queue->Begin = new Double_List();
  326. End_Queue->Begin->Data = NewElem;
  327. End_Queue->Begin->Prior = NULL;
  328. End_Queue->Begin->Next = NULL;
  329. End_Queue->End = End_Queue->Begin;
  330. return;
  331. }
  332. End_Queue->End = Insert_Item_Double_List(End_Queue->End, 1, NewElem)->Next;
  333. }
  334.  
  335. bool Empty_Queue(Ochered* Begin_Queue)
  336. {
  337. return Empty_Double_List(Begin_Queue->Begin);
  338. }
  339.  
  340. void Clear_Queue(Ochered* Begin_Queue)
  341. {
  342. return Delete_Double_List(Begin_Queue->Begin);
  343. }
  344.  
  345. int Extract_Item_Queue(Ochered* Begin_Queue)
  346. {
  347. int NewElem;
  348. if(Begin_Queue->Begin->Next != NULL)
  349. {
  350. NewElem = Begin_Queue->Begin->Data;
  351. Begin_Queue->Begin = Delete_Item_Double_List(Begin_Queue->Begin, 1);
  352. }
  353. else
  354. {
  355. NewElem = Begin_Queue->Begin->Data;
  356. Begin_Queue->Begin = NULL;
  357. }
  358. return NewElem;
  359. }
  360.  
  361. bool krat3(int el)
  362. {
  363. for(int i = 2; i < el; i++)
  364. if(el%3==0)
  365. return false;
  366. return true;
  367. }
  368. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  369. int A, k;
  370. textBox1->Text = "";
  371. textBox3->Text = "";
  372. if(textBox2->Text == "")
  373. k = 10;
  374. else
  375. k = Convert::ToInt32(textBox2->Text);
  376. for(int i = 0; i < k; i++)
  377. {
  378. A = rand()%100+0;
  379. textBox1->Text += (A + " ");
  380. }
  381. }
  382. private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
  383. textBox3->Text = "";
  384. String ^ first_string, ^ chislo;
  385. Ochered *My_Queue = new Ochered();
  386. first_string = textBox1->Text;
  387. int i = 0;
  388. while(i < first_string->Length)
  389. {
  390. chislo = "";
  391. while(first_string[i] != ' ')
  392. {
  393. chislo += first_string[i];
  394. i++;
  395. if(i >= first_string->Length)
  396. break;
  397. }
  398. Add_Item_Queue(Convert::ToInt32(chislo), My_Queue);
  399. if(i >= first_string->Length)
  400. break;
  401. while(first_string[i] == ' ')
  402. {
  403. i++;
  404. if(i >= first_string->Length)
  405. break;
  406. }
  407. }
  408. int buf;
  409. while(My_Queue->Begin != NULL)
  410. {
  411. buf = Extract_Item_Queue(My_Queue);
  412. if(krat3(buf))
  413. textBox3->Text += (buf + " ");
  414. }
  415. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement