Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. //Do not forget to change a little...
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. class copy_pasted{
  9. public:
  10. string label;
  11. string symbol;
  12. int address;
  13. copy_pasted *next = NULL;
  14. copy_pasted() = default;
  15. copy_pasted(const string &l, const string &s, int ad) : label(l), symbol(s), address(ad) {};
  16. };
  17. copy_pasted *first = NULL, *last = NULL;
  18.  
  19. void Display(copy_pasted *cur){
  20. cout << left;
  21. cout << setw(15)<<"Label" <<setw(15)<< "Symbol" <<setw(15)<<"Address" << endl;
  22. while(cur != NULL){
  23. cout << setw(15)<< cur->label << setw(15)<< cur->symbol << setw(15)<< cur->address << endl;
  24. cur = cur->next;
  25. }
  26. }
  27.  
  28. void Insert(){
  29. copy_pasted *cur = last;
  30. string s, l;
  31. int a;
  32. cout << "Enter Label: ";
  33. cin >> l;
  34. cout << "Enter Symbol: ";
  35. cin >> s;
  36. cout << "Enter Address: ";
  37. cin >> a;
  38. copy_pasted *r = new copy_pasted(l, s, a);
  39. if(first == NULL)
  40. first = r;
  41. else
  42. cur->next = r;
  43. last = r;
  44. }
  45.  
  46. copy_pasted * Find(string a){
  47. copy_pasted *cur = first;
  48. while(cur != NULL){
  49. if(cur->label == a)
  50. return cur;
  51. cur = cur->next;
  52. }
  53. return NULL;
  54. }
  55.  
  56. void Edit(){
  57. string label;
  58. cout << "Enter label to update: ";
  59. cin >> label;
  60. copy_pasted *cur = Find(label);
  61. if(cur == NULL){
  62. cout << "Label not found!" << endl;
  63. return;
  64. }
  65. string s, l;
  66. int a;
  67. cout << "Enter new Label: ";
  68. cin >> l;
  69. cout << "Enter new Symbol: ";
  70. cin >> s;
  71. cout << "Enter new Address: ";
  72. cin >> a;
  73. cur->label = l;
  74. cur->symbol = s;
  75. cur->address = a;
  76. }
  77.  
  78. void Delete(){
  79. string label;
  80. cout << "Enter label to delete: ";
  81. cin >> label;
  82. copy_pasted *cur = Find(label);
  83. if(cur == NULL){
  84. cout << "Label not found!" << endl;
  85. return;
  86. }
  87. auto pre = first, temp = first;
  88. while(temp != cur){
  89. pre = temp;
  90. temp = temp->next;
  91. }
  92. pre->next = cur->next;
  93. if(cur == first)
  94. first = cur->next;
  95. delete (cur);
  96. }
  97.  
  98. void Search(){
  99. string label;
  100. cout << "Enter label to delete: ";
  101. cin >> label;
  102. copy_pasted *cur = Find(label);
  103. if(cur == NULL){
  104. cout << "Label not found!" << endl;
  105. return;
  106. }
  107. copy_pasted *temp = new copy_pasted(cur->label, cur->symbol, cur -> address);
  108. Display(temp);
  109. delete (temp);
  110. }
  111.  
  112. void run()
  113. {
  114. int op;
  115. do
  116. {
  117. printf("\nSYMBOL TABLE IMPLEMENTATION\n");
  118. printf("\n1.INSERT\n2.DISPLAY\n3.DELETE\n4.SEARCH\n5.EDIT\n6.END\n");
  119. printf("\nEnter your option : ");
  120. scanf("%d", &op);
  121.  
  122. switch (op)
  123. {
  124. case 1:
  125. Insert();
  126. break;
  127. case 2:
  128. Display(first);
  129. break;
  130. case 3:
  131. Delete();
  132. break;
  133. case 4:
  134. Search();
  135. break;
  136. case 5:
  137. Edit();
  138. break;
  139. case 6:
  140. exit(0);
  141. }
  142.  
  143. } while (1);
  144. }
  145.  
  146. int main(){
  147. run();
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement