-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeader.h
1202 lines (1040 loc) · 26.5 KB
/
Header.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include<math.h>
#include<iostream>
#include<vector>
#include<functional>
#include<fstream>
#include<algorithm>
#include<sstream>
using namespace std;
struct IdentifierNode;
struct AVL_Information_Node //AVL Tree Node
{
int key = 0;
int Row_No = 0;
string path = "";
AVL_Information_Node* left;
AVL_Information_Node* right;
int height = 0;
};
/* AVL class
Purpose: it is used to store All data entered by the user and and contain address of all data
*/
class AVL_Information
{
public:
int counting = 0; //for counting purpose to trace how many records are stored in the file
AVL_Information_Node* root; //root of AVL tree
AVL_Information() //constractor
{
root = NULL;
}
void makeEmpty(AVL_Information_Node* temp) //to delete the tree
{
if (temp == NULL)
return;
makeEmpty(temp->left);
makeEmpty(temp->right);
delete temp;
}
AVL_Information_Node*& Insert(int ke, string p, AVL_Information_Node*& temp, string data, string orginal_key) //to insert the data
{
if (temp == NULL)
{
temp = new AVL_Information_Node;
fstream file;
file.open(p, ios::app); //opening file in append mode
file << orginal_key << " " << data << endl;
counting++;
file.close();
temp->key = ke;
temp->Row_No = counting;
temp->path = p;
temp->height = 0;
temp->left = temp->right = NULL;
}
else if (ke < temp->key) //less then
{
temp->left = Insert(ke, p, temp->left, data, orginal_key);
if (height(temp->left) - height(temp->right) == 2)
{
if (ke < temp->left->key)
{
temp = Single_R(temp);
}
else
{
temp = Double_R(temp);
}
}
}
else if (ke > temp->key) // greater then
{
temp->right = Insert(ke, p, temp->right, data, orginal_key);
if (height(temp->right) - height(temp->left) == 2)
{
if (ke > temp->right->key)
temp = Single_L(temp);
else
temp = Double_L(temp);
}
}
temp->height = max(height(temp->left), height(temp->right)) + 1; //balancing height
return temp;
}
AVL_Information_Node* Minimum(AVL_Information_Node*& temp) // to find min in tree
{
if (temp == NULL)
{
return NULL;
}
else if (temp->left == NULL)
{
return temp;
}
else
{
return Minimum(temp->left);
}
}
AVL_Information_Node* Maximum(AVL_Information_Node*& temp) // to find max in tree
{
if (temp == NULL)
{
return NULL;
}
else if (temp->right == NULL)
{
return temp;
}
else
{
return Maximum(temp->right);
}
}
AVL_Information_Node* Delete(int key, AVL_Information_Node*& temp, string orginal_key) //to delete record
{
AVL_Information_Node* current;
if (temp == NULL)
{
cout << "Given input \"" << key << "\" is not found" << endl << endl;
return NULL;
}
else if (key < temp->key)
{
temp->left = Delete(key, temp->left, orginal_key);
}
else if (key > temp->key)
{
temp->right = Delete(key, temp->right, orginal_key);
}
else if (temp->left && temp->right)
{
current = Minimum(temp->right);
temp->key = current->key;
temp->right = Delete(temp->key, temp->right, orginal_key);
}
else
{
current = temp;
if (temp->left == NULL)
{
temp = temp->right;
}
else if (temp->right == NULL)
{
temp = temp->left;
}
string reading1, reading2;
int cou = -1;
fstream file;
fstream file1("tempray.txt", ios::app);
file.open(current->path, ios::in);
while (!file.eof()) //copying all data in tempary file except which we want to delete
{
string str1, str2;
file >> str1;
file >> str2;
cout << str1 << " " << str2 << endl;
if (str1 == orginal_key)
{
}
else
{
file1 << str1 << " " << str2 << endl;
cou++;
}
}
file.close();
file1.close();
ofstream file3;
ifstream file2("tempray.txt");
file3.open(current->path, ios::out | ios::trunc);
file3.close();
file3.open(current->path, ios::out | ios::app);
string str1 = "", str2 = "";
while (cou > 0) { //again restoring all data in original file
file2 >> str1;
file2 >> str2;
file3 << str1 << " " << str2 << endl;
cou--;
}
file2.close();
file3.close();
file3.open("tempray.txt", ios::out | ios::trunc);
file3.close();
delete current;
}
if (temp == NULL)
{
return temp;
}
temp->height = max(height(temp->left), height(temp->right)) + 1;
if (height(temp->left) - height(temp->right) == -2)
{
if (height(temp->right->right) - height(temp->right->left) == 1)
return Single_L(temp);
else
return Double_L(temp);
}
else if (height(temp->right) - height(temp->left) == 2)
{
if (height(temp->left->left) - height(temp->left->right) == 1) {
return Single_R(temp);
}
else
return Double_R(temp);
}
return temp;
}
AVL_Information_Node*& Single_R(AVL_Information_Node*& temp) //single right shift
{
AVL_Information_Node* current = temp->left;
temp->left = current->right;
current->right = temp;
temp->height = max(height(temp->left), height(temp->right)) + 1;
current->height = max(height(current->left), temp->height) + 1;
return current;
}
AVL_Information_Node*& Single_L(AVL_Information_Node*& temp) //single left shift
{
AVL_Information_Node* current = temp->right;
temp->right = current->left;
current->left = temp;
temp->height = max(height(temp->left), height(temp->right)) + 1;
current->height = max(height(temp->right), temp->height) + 1;
return current;
}
AVL_Information_Node*& Double_L(AVL_Information_Node*& temp) //double left shift
{
temp->right = Single_R(temp->right);
return Single_L(temp);
}
AVL_Information_Node*& Double_R(AVL_Information_Node*& temp) //double right shift
{
temp->left = Single_L(temp->left);
return Single_R(temp);
}
int height(AVL_Information_Node*& temp) //to get hieght of tree
{
if (temp == NULL)
{
return -1;
}
else
temp->height;
}
void searching_Data(int ke, AVL_Information_Node*& temp, string orginal_key, bool flag) //to search data using Key
{
if (temp == NULL)
{
return;
}
searching_Data(ke, temp->left, orginal_key, flag);
if (ke == temp->key)
{
string reading1, reading2;
fstream file;
file.open(temp->path);
for (int i = 1; i <= temp->Row_No; i++)
{
file >> reading1;
file >> reading2;
if (orginal_key == reading1)
{
cout << "Key is: " << reading1 << " Coressponding Data: " << reading2 << endl;
flag = false;
file.close();
}
}
}
if (flag)
cout << "Record is Not Found!" << endl;
searching_Data(ke, temp->right, orginal_key, flag);
return;
}
void reading_AVL(AVL_Information_Node*& temp, IdentifierNode* temp1, int count); //reading All record stored on AVL of a Machine
void show_AVL(AVL_Information_Node* temp) //printing AVL of a Machine
{
if (temp == NULL)
return;
show_AVL(temp->left);
cout << "Key: " << temp->key << " Row number: " << temp->Row_No << " path: " << temp->path << endl;
show_AVL(temp->right);
}
};
//distribution Hashing Table Node
struct DHT_Node {
int serial_no;
int Machine_id;
IdentifierNode* M_pointer;
DHT_Node* next, * prev;
};
// DHT class
class DHT {
public:
DHT_Node* DHT_head, * DHT_tail;
DHT() // constractor
{
DHT_head = NULL;
DHT_tail = NULL;
}
void insertion(int serial, int id, IdentifierNode*& M_node) { //inserting information in DHT
DHT_Node* temp = new DHT_Node;
temp->serial_no = serial;
temp->Machine_id = id;
temp->M_pointer = M_node;
temp->next = NULL;
if (DHT_head == NULL)
{
DHT_head = temp;
DHT_tail = temp;
}
else
{
DHT_tail->next = temp;
DHT_tail = DHT_tail->next;
}
}
void Delete_DHT() { //Deleting DHTs
DHT_Node* temp;
while (DHT_head != NULL) {
temp = DHT_head->next;
delete DHT_head;
DHT_head = temp;
}
}
void DHT_Display(); //Displaying DHTs
};
struct IdentifierNode {
int ID;
AVL_Information Data_keys;
DHT Table;
int handling_count = 0;
vector<int> handling_nodes;
IdentifierNode* next;
};
void DHT::DHT_Display() {
DHT_Node* temp = DHT_head;
while (temp != NULL) {
cout << temp->serial_no << " " << temp->Machine_id << endl;
temp = temp->next;
}
}
/* Indentifier Space class
* purpose: this will sepacify all the gievn space
* all the information related to machines
* linkedlist of all the machines in the space
*
*
* */
class Identifierspace {
public:
int Total_No_Machine;
vector<int> Machines_IDs;
int count;
int space_bits;
IdentifierNode* head, * tail;
Identifierspace()
{
space_bits = 0;
count = 0;
Total_No_Machine = 0;
head = NULL;
tail = NULL;
}
void get_count(int n) //Totall places in space
{
n--;
count = n;
}
void set_bit(int n) //Totall bits in space
{
space_bits = n;
}
void Delete_Machine(int value, int count) { //delete a machine
IdentifierNode* temp = new IdentifierNode;
int position = 0;
temp = head;
for (int i = 0; i < Total_No_Machine; i++) {
if (temp->ID == value) {
break;
}
position++;
temp = temp->next;
}
IdentifierNode* temp1 = head;
for (int i = 1; i < position; i++)
{
temp1 = temp1->next;
}
if (temp != head)
{
temp1->next = temp->next;
temp->Data_keys.reading_AVL(temp->Data_keys.root, temp->next, count);
delete temp;
}
if (temp == head)
{
tail->next = head->next;
head = head->next;
temp->Data_keys.reading_AVL(temp->Data_keys.root, temp->next, count);
delete temp;
}
}
void Machine_DHT_Display() //printing DHT of a Machine
{
int id = 0;
IdentifierNode* temp;
temp = head;
cout << "Enter ID of Machine you want to display DHT " << endl;
cin >> id;
while (1) //check to restrict the user for a spacific input
{
for (int i = 0; i < Total_No_Machine; i++)
{
if (id == Machines_IDs[i])
goto outside;
}
cout << "Wrong input! Try again: " << endl;
cin >> id;
}
outside:
for (int i = 0; i < Total_No_Machine; i++) //dispalying loop
{
if (temp->ID == id)
{
temp->Table.DHT_Display();
}
temp = temp->next;
}
}
void Deleting_DHTs() //deleting
{
IdentifierNode* temp;
temp = head;
for (int i = 0; i < Total_No_Machine; i++)
{
temp->Table.Delete_DHT();
temp = temp->next;
}
}
void Genratiing_DHTs() //Genration og DHTs of all the machines
{
int genrated = 0, get_id = 0;
IdentifierNode* temp, * temp1, * temp2;
temp1 = head;
for (int i = 0; i < Total_No_Machine; i++)
{
for (int j = 1; j <= space_bits; j++)
{
genrated = (temp1->ID + (pow(2, j - 1)));
genrated = genrated % (count + 1);
temp = head;
for (int k = 0; k < Total_No_Machine; k++)
{
for (int h = 0; h < temp->handling_nodes.size(); h++)
{
if (temp->handling_nodes[h] == genrated)
{
temp2 = temp;
get_id = temp->ID;
goto out;
}
}
temp = temp->next;
}
out:
temp1->Table.insertion(j, get_id, temp2);
}
temp1 = temp1->next;
}
}
void Creation_of_Machine(double value) { //creation of Machines :public function of class
IdentifierNode* temp = new IdentifierNode;
temp->ID = value;
temp->next = head;
if (head == NULL) {
head = temp;
tail = temp;
}
else {
tail->next = temp;
tail = tail->next;
}
}
void Add_Machine(int n) //adding machine : public function of class
{
Total_No_Machine = Total_No_Machine + n;
}
void islistEmpty() {
if (head == NULL) {
cout << "list is empty" << endl;
}
else
cout << "List is not empty" << endl;
}
void display_handling_IDs_by_Machine() //displaying all the space handled by a machine
{
IdentifierNode* temp;
temp = head;
for (int i = 0; i < Total_No_Machine; i++)
{
cout << "Machine: ";
cout << "ID " << temp->ID << endl;
for (int k = 0; k < temp->handling_nodes.size(); k++)
{
cout << temp->handling_nodes[k] << " ";
}
cout << endl;
temp = temp->next;
}
}
};
void storing_in_AVL(string s1, IdentifierNode*& temp, string Data, string Key, int AVL_key, string orginal_key) //gernal function to call insert function(public function of class)
{
string convert = to_string(temp->ID);
s1 = s1 + convert;
s1 = s1 + ".txt";
temp->Data_keys.Insert(AVL_key, s1, temp->Data_keys.root, Data, orginal_key);
}
void searching_in_AVL(IdentifierNode*& temp, int AVL_key, string orginal_key) //gernal function to call searching Data function (public)
{
temp->Data_keys.searching_Data(AVL_key, temp->Data_keys.root, orginal_key, true);
}
void Deleting_Data(int ke, IdentifierNode*& temp, string orginal_key) //gernal function to call delete function(public)
{
temp->Data_keys.Delete(ke, temp->Data_keys.root, orginal_key);
}
/*
gernal purpose function to find a machine using spacific
data to help in (searching,inserting and deleting proccess
*/
IdentifierNode*& finding_machine(IdentifierNode*& temp, Identifierspace& obj, int AVL_key)
{
DHT_Node* temp1, * temp2;
temp2 = temp->Table.DHT_head;
repeat:
temp1 = temp->Table.DHT_head;
for (int i = 0; i < obj.space_bits - 1; i++)
{
if (AVL_key > temp1->Machine_id && temp1->next->Machine_id >= AVL_key) // if machine is founded where data is to be stored
{
return temp1->M_pointer; //returnning required machine pointer
}
temp1 = temp1->next;
temp2 = temp1;
}
temp = temp->Table.DHT_head->M_pointer;
for (int i = 0; i < temp->handling_nodes.size(); i++)
{
if (AVL_key == temp->handling_nodes[i])
{
return temp;
}
}
//if Machine is not founded in DHT Table/ setting last machine head in Table to check again
goto repeat;
}
void Search_Data(string Key, Identifierspace& obj, int Machine_id) //searching data
{
int AVL_key = 0;
hash<string> hashing;
IdentifierNode* temp, * temp1;
temp1 = obj.head;
temp = obj.head;
repeat:;
for (int i = 0; i < obj.Total_No_Machine; i++)
{
if (Machine_id == temp->ID)
{
AVL_key = hashing(Key);
if (AVL_key < 0)
AVL_key = -AVL_key;
AVL_key = AVL_key % (obj.count + 1);
for (int j = 0; j < temp->handling_nodes.size(); j++)
{
if (temp->handling_nodes[j] == AVL_key)
{
searching_in_AVL(temp, AVL_key, Key);
goto outside;
}
}
temp1 = temp;
}
temp = temp->next;
}
temp = finding_machine(temp1, obj, AVL_key);
Machine_id = temp->ID;
goto repeat;
outside:;
}
void Deleting(string Key, Identifierspace& obj, int Machine_id) //gernal function
{
int AVL_key = 0;
hash<string> hashing;
IdentifierNode* temp, * temp1;
temp = obj.head;
repeat:;
for (int i = 0; i < obj.Total_No_Machine; i++)
{
if (Machine_id == temp->ID)
{
AVL_key = hashing(Key);
if (AVL_key < 0)
AVL_key = -AVL_key;
AVL_key = AVL_key % (obj.count + 1);
for (int j = 0; j < temp->handling_nodes.size(); j++)
{
if (temp->handling_nodes[j] == AVL_key)
{
Deleting_Data(AVL_key, temp, Key);
goto outside;
}
}
temp1 = temp;
}
temp = temp->next;
}
temp = finding_machine(temp1, obj, AVL_key);
Machine_id = temp->ID;
goto repeat;
outside:;
}
void Store_Data(string Key, string Data, Identifierspace& obj, int Machine_id) //gernal function storing information in AVl of machine
{
int AVL_key = 0;
hash<string> hashing;
IdentifierNode* temp, * temp1;
string s1 = "Machine", s2 = ".txt";
temp = obj.head;
temp1 = obj.head;
repeat:;
for (int i = 0; i < obj.Total_No_Machine; i++)
{
if (Machine_id == temp->ID)
{
AVL_key = hashing(Key);
if (AVL_key < 0)
AVL_key = -AVL_key;
AVL_key = AVL_key % (obj.count + 1);
cout << "hashing " << AVL_key << endl;
for (int j = 0; j < temp->handling_nodes.size(); j++) //e==p
{
if (temp->handling_nodes[j] == AVL_key)
{
storing_in_AVL(s1, temp, Data, Key, AVL_key, Key);
goto outside;
}
}
temp1 = temp;
if (temp->ID < AVL_key && AVL_key <= temp->Table.DHT_head->Machine_id)
{
temp = temp->Table.DHT_head->M_pointer;
for (int j = 0; j < temp->handling_nodes.size(); j++) //e>last machine ID
{
if (temp->handling_nodes[j] == AVL_key)
{
storing_in_AVL(s1, temp, Data, Key, AVL_key, Key);
goto outside;
}
}
}
}
temp = temp->next;
}
temp = finding_machine(temp1, obj, AVL_key);
Machine_id = temp->ID;
goto repeat;
outside:;
}
/*
* spacifying total space
*seting space variable
* seting bits in space
*/
void insert(int n, Identifierspace& obj)
{
int p;
p = pow(2, n);
obj.set_bit(n);
obj.get_count(p);
}
void Delete_Machine_on_Fly(Identifierspace& obj) //deleting machine on run time
{
int input, match1 = 0;
IdentifierNode* temp, * temp1;
cout << "Enter ID of Machine which you want to Delete: " << endl;
cin >> input;
while (1)
{
for (int i = 0; i < obj.Total_No_Machine; i++)
{
if (input == obj.Machines_IDs[i])
goto outside;
}
cout << "Wrong input! Try again: " << endl;
cin >> input;
}
outside:
temp1 = obj.head;
temp = obj.head;
for (int i = 0; i < obj.Total_No_Machine; i++)
{
if (obj.Machines_IDs[i] == input && (obj.Machines_IDs[obj.Machines_IDs.size() - 1]) != input)
{
match1 = obj.Machines_IDs[i + 1];
remove(obj.Machines_IDs.begin(), obj.Machines_IDs.end(), input);
}
else if (obj.Machines_IDs[obj.Machines_IDs.size() - 1] == input)
{
match1 = obj.Machines_IDs[0];
remove(obj.Machines_IDs.begin(), obj.Machines_IDs.end(), 0);
}
}
for (int i = 0; i < obj.Total_No_Machine; i++)
{
if (temp->ID == input)
{
for (int i = 0; i < obj.Total_No_Machine; i++)
{
if (temp1->ID == match1)
{
for (int k = (temp->handling_nodes.size() - 1); k >= 0; k--)
{
temp1->handling_nodes.insert(temp1->handling_nodes.begin(), temp->handling_nodes[k]);
}
obj.Deleting_DHTs();
obj.Delete_Machine(input, obj.count);
obj.Total_No_Machine--;
obj.Genratiing_DHTs();
goto outside1;
}
temp1 = temp1->next;
}
}
temp = temp->next;
}
outside1:;
}
void Add_Machine_on_Fly(Identifierspace& obj) //adding machine on run time
{
obj.Deleting_DHTs();
int input, input2;
IdentifierNode* temp, * temp1, * temp2;
vector<int> var1;
cout << "Please Enter ID of New Machine: " << endl;
cin >> input;
again:
for (int i = 0; i < obj.Machines_IDs.size(); i++)
{
if (obj.Machines_IDs[i] == input)
{
cout << "this ID is Already Registered! Please Try Again;- " << endl;
cin >> input;
goto again;
}
}
temp = obj.head;
temp2 = obj.tail;
for (int i = 0; i < obj.Total_No_Machine; i++)
{
for (int j = 0; j < temp->handling_nodes.size(); j++)
{
if (temp->handling_nodes[j] == input)
{
obj.Creation_of_Machine(input);
obj.Machines_IDs.push_back(input);
for (int i = 0; i < obj.Machines_IDs.size(); i++)
{
sort(obj.Machines_IDs.begin(), obj.Machines_IDs.end());
}
obj.Add_Machine(1);
temp1 = obj.head;
for (int k = 0; k < obj.Total_No_Machine; k++)
{
if (temp1->ID == input)
{
for (int l = 0; l < temp->handling_nodes.size(); l++)
{
if (temp->handling_nodes[l] <= input)
temp1->handling_nodes.push_back(temp->handling_nodes[l]);
else if (temp->handling_nodes[l] > input)
temp1->handling_nodes.push_back(temp->handling_nodes[l]);
if (temp->handling_nodes[l] == input)
{
input2 = l;
input2++;
goto stop;
}
// var1.push_back(temp->handling_nodes[l]);
}
stop:
for (input2; input2 < temp->handling_nodes.size(); input2++)
{
var1.push_back(temp->handling_nodes[input2]);
}
temp->handling_nodes.clear();
temp->handling_nodes = var1;
goto outside;
}
temp2 = temp1;
temp1 = temp1->next;
}
}
}
temp = temp->next;
}
obj.Genratiing_DHTs();
outside:;
}
void Creat_Machines(int n, Identifierspace& obj) //create machine manually at start of program
{
vector<int> index; //vector to store indexes which user enter
IdentifierNode* temp, * temp1;
int input, input1 = 0, var1 = 0;
string Name = "";
for (int i = 0; i < n; i++) // taking input from user
{
cout << "Enter ID number where you want to create a Machine " << i + 1 << endl;
cin >> input;
while (input<0 || input>obj.count + 1)
{
cout << "Wrong input ID Please Try Again! " << endl;
cin >> input;
}
again:
for (int i = 0; i < index.size(); i++)
{
if (index[i] == input)
{
cout << "this ID is Already registered! Please Try Again;- " << endl;
cin >> input;
goto again;
}
}
index.push_back(input);
}
for (int i = 0; i < index.size(); i++) //sorting
{
sort(index.begin(), index.end());
}
obj.Machines_IDs = index;
for (int i = 0; i < n; i++) //creating machine
{
obj.Creation_of_Machine(index[i]);
}
temp = obj.head;
if (obj.Total_No_Machine > 1)
{
for (int i = 0; i < n; i++)
{
temp1 = obj.head;
input = temp->ID;
for (int j = 0; j < obj.Total_No_Machine; j++)
{
if (temp1->next->ID == input)
{
input1 = temp1->ID; //ID of previous machine
}
temp1 = temp1->next;
}
if (input1 == obj.count)
{
input1 = 0;
for (int k = input1; k <= input; k++)
{
temp->handling_nodes.push_back(k);
}
}