Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need Help with homework ( on symbol tables ) A) Update your code to support these changes. remove all occurrences of label. (keep symbol) change

Need Help with homework ( on symbol tables )

A) Update your code to support these changes.

remove all occurrences of "label". (keep symbol) change "symbol[10]" to char * symbol;

B)Change the following functions to have these prototypes

struct SymbTab * Insert(char *symbol, int address); PRE: PTr to character string, POST, PTR to structure new symbol. Error message and exit if already present.

struct SymbTab * Search(char *symbol ); PRE Ptr character string, POST: PTR to matching structure or NULL

C)Create a symbtab.h files which exposes the Insert() and Search() and struct{} definition

/******************************************************************************************************/

#include

#include

#include

#include

int size = 0;

void Insert();

void Display();

void Delete();

int Search(char lab[]);

void Modify();

struct SymbTab

{

char label[10], symbol[10];

int addr;

struct SymbTab *next;

};

struct SymbTab *first, *last;

void main()

{

int op, y;

char la[10];

do

{

printf(" \tSYMBOL TABLE IMPLEMENTATION ");

printf(" \t1.INSERT \t2.DISPLAY \t3.DELETE \t4.SEARCH \t5.MODIFY \t6.END ");

printf(" \tEnter your option : ");

scanf("%d", &op);

switch (op)

{

case 1:

Insert();

break;

case 2:

Display();

break;

case 3:

Delete();

break;

case 4:

printf(" \tEnter the label to be searched : ");

scanf("%s", la);

y = Search(la);

printf(" \tSearch Result:");

if (y == 1)

printf(" \tThe label is present ");

else

printf(" \tThe label is not present ");

break;

case 5:

Modify();

break;

case 6:

exit(0);

}

} while (op < 6);

} /* end of main */

void Insert()

{

int n;

char l[10];

printf(" \tLabel? : ");

scanf("%s", l);

n = Search(l);

if (n == 1)

printf(" \tThe label exists already \tDuplicate cant be inserted in the symbol table");

else

{

struct SymbTab *p;

p = malloc(sizeof(struct SymbTab));

strcpy(p->label, l);

printf(" \tEnter the symbol : ");

scanf("%s", p->symbol);

printf(" \tEnter the address : ");

scanf("%d", &p->addr);

p->next = NULL;

if (size == 0)

{

first = p;

last = p;

}

else

{

last->next = p;

last = p;

}

size++;

}

printf(" \tLabel inserted ");

}

void Display()

{

int i;

struct SymbTab *p;

p = first;

printf(" \tLABEL\t\tSYMBOL\t\tADDRESS ");

for (i = 0; i < size; i++)

{

printf("\t%s\t\t%s\t\t%d ", p->label, p->symbol, p->addr);

p = p->next;

}

}

int Search(char lab[])

{

int i, flag = 0;

struct SymbTab *p;

p = first;

for (i = 0; i < size; i++)

{

if (strcmp(p->label, lab) == 0)

flag = 1;

p = p->next;

}

return flag;

}

void Erase()

{

int a;

char l[10];

struct SymbTab *p, *q;

p = first;

printf(" \tWhat do you want to Erase : ");

scanf("%s", l);

a = Search(l);

if (a == 0)

printf(" \tnot found ");

else

{

if (strcmp(first->label, l) == 0)

first = first->next;

else if (strcmp(last->label, l) == 0)

{

q = p->next;

while (strcmp(q->label, l) != 0)

{

p = p->next;

q = q->next;

}

p->next = NULL;

last = p;

}

else

{

q = p->next;

while (strcmp(q->label, l) != 0)

{

p = p->next;

q = q->next;

}

p->next = q->next;

}

size--;

printf(" \tLabel is now: ");

Display();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions