Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Do not forget to change a little...
- #include<bits/stdc++.h>
- using namespace std;
- class copy_pasted{
- public:
- string label;
- string symbol;
- int address;
- copy_pasted *next = NULL;
- copy_pasted() = default;
- copy_pasted(const string &l, const string &s, int ad) : label(l), symbol(s), address(ad) {};
- };
- copy_pasted *first = NULL, *last = NULL;
- void Display(copy_pasted *cur){
- cout << left;
- cout << setw(15)<<"Label" <<setw(15)<< "Symbol" <<setw(15)<<"Address" << endl;
- while(cur != NULL){
- cout << setw(15)<< cur->label << setw(15)<< cur->symbol << setw(15)<< cur->address << endl;
- cur = cur->next;
- }
- }
- void Insert(){
- copy_pasted *cur = last;
- string s, l;
- int a;
- cout << "Enter Label: ";
- cin >> l;
- cout << "Enter Symbol: ";
- cin >> s;
- cout << "Enter Address: ";
- cin >> a;
- copy_pasted *r = new copy_pasted(l, s, a);
- if(first == NULL)
- first = r;
- else
- cur->next = r;
- last = r;
- }
- copy_pasted * Find(string a){
- copy_pasted *cur = first;
- while(cur != NULL){
- if(cur->label == a)
- return cur;
- cur = cur->next;
- }
- return NULL;
- }
- void Edit(){
- string label;
- cout << "Enter label to update: ";
- cin >> label;
- copy_pasted *cur = Find(label);
- if(cur == NULL){
- cout << "Label not found!" << endl;
- return;
- }
- string s, l;
- int a;
- cout << "Enter new Label: ";
- cin >> l;
- cout << "Enter new Symbol: ";
- cin >> s;
- cout << "Enter new Address: ";
- cin >> a;
- cur->label = l;
- cur->symbol = s;
- cur->address = a;
- }
- void Delete(){
- string label;
- cout << "Enter label to delete: ";
- cin >> label;
- copy_pasted *cur = Find(label);
- if(cur == NULL){
- cout << "Label not found!" << endl;
- return;
- }
- auto pre = first, temp = first;
- while(temp != cur){
- pre = temp;
- temp = temp->next;
- }
- pre->next = cur->next;
- if(cur == first)
- first = cur->next;
- delete (cur);
- }
- void Search(){
- string label;
- cout << "Enter label to delete: ";
- cin >> label;
- copy_pasted *cur = Find(label);
- if(cur == NULL){
- cout << "Label not found!" << endl;
- return;
- }
- copy_pasted *temp = new copy_pasted(cur->label, cur->symbol, cur -> address);
- Display(temp);
- delete (temp);
- }
- void run()
- {
- int op;
- do
- {
- printf("\nSYMBOL TABLE IMPLEMENTATION\n");
- printf("\n1.INSERT\n2.DISPLAY\n3.DELETE\n4.SEARCH\n5.EDIT\n6.END\n");
- printf("\nEnter your option : ");
- scanf("%d", &op);
- switch (op)
- {
- case 1:
- Insert();
- break;
- case 2:
- Display(first);
- break;
- case 3:
- Delete();
- break;
- case 4:
- Search();
- break;
- case 5:
- Edit();
- break;
- case 6:
- exit(0);
- }
- } while (1);
- }
- int main(){
- run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement