#include void exit(int); typedef struct webpage { int wpnumber; // Web page id struct webpage* nextwp; // Pointer to web page struct itarray { int indexterm; // Indexterm struct webpage* wplink; // Pointer to web page } itl[2]; } Webpage; typedef struct indexterm { int itnumber; //Index term id int numberoftimes; //# of web pages that include itnumber Webpage* link2webpage; //Pointer to web page struct indexterm* nextit; //Pointer to index term } Indexterms; // The following function takes as input a pointer to the first element // in the web pages list and an integer m and returns a pointer to the // instance of struct webpage that represent web page m, or NULL (zero) // if the web page is not in the list. struct webpage *find(struct webpage *p, int m) {struct webpage *q; if (p == NULL) return NULL; q = p; while (q != NULL) { if (q->wpnumber == m) return q; if (q->wpnumber > m) return NULL; if (q->wpnumber < m) q = q->nextwp; } return q; } int main(void) { int m,i1,i2; char t; // ... while(1==1) {t=getchar(); switch(t) { case('i'): {scanf("%d %d %d",&m,&i1,&i2); printf("i %d %d %d\n", m, i1, i2); /* Should invoke a function to insert a web page*/ break;} case('d'): {scanf("%d",&m); printf("d %d\n",m); /* Should invoke a function to delete a web page */ break;} // ... case('l'): {printf("l\n"); /* Should invoke a function to print the correct number */ break;} // ... case('q'): {printf("q\n"); // need to delete lists exit(0);} } if('\n' != getchar()) exit(1); } } // The following function takes as input a pointer to the first element // in the index terms list and an integer i1, and returns the number // of web pages containing index term i1. If the index term is not // in the system, it returns zero. int count(struct indexterm *ip, int i1) {struct indexterm *iq; struct webpage *q; int counter; // Find first web page if (ip == NULL) return 0; iq = ip; while (iq != NULL) { if (iq->itnumber == i1) break; if (iq->itnumber > i1) return 0; if (iq->itnumber < i1) iq = iq->nextit; } if (iq == NULL) return 0; // Found the first web page so now count all the // web pages that contian index term i1 counter = 0; q = iq->link2webpage; while (q != NULL) {counter++; if (i1 == q->itl[0].indexterm) q = q->itl[0].wplink; else q = q->itl[1].wplink; } return counter; }