Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define numbOfList 4
- #define numbOfChars 50
- struct symbolInfo{
- char name[numbOfChars];
- char ID[numbOfChars];
- char CGPA[numbOfChars];
- struct symbolInfo *next;
- }*symbolTable[numbOfList];
- void displayAll(){
- printf("Displaying the list :- \n");
- struct symbolInfo *isNull;
- int i;
- for(i=0; i<numbOfList; i++){
- isNull=symbolTable[i];
- printf("\n%d No. list : ", i+1);
- while(isNull!=NULL){
- printf("<%s,%s, %s> ",isNull->name, isNull->ID, isNull->CGPA);
- isNull=isNull->next;
- }
- }
- printf("\n");
- }
- void insert(char setName[numbOfChars], char setID[numbOfChars], char setCGPA[numbOfChars] ,int hashKey){
- struct symbolInfo *isNull;
- struct symbolInfo *temp;
- isNull = symbolTable[hashKey];
- temp = malloc(sizeof(struct symbolInfo));
- temp -> next = NULL;
- strcpy(temp->name, setName);
- strcpy(temp->ID, setID);
- strcpy(temp->CGPA, setCGPA);
- symbolTable[hashKey] = temp;
- symbolTable[hashKey] ->next = isNull; //assume, symbolTable[hashKey] == head
- }
- void deleteFromList(char getName[numbOfChars], char getID[numbOfChars],char getCGPA[numbOfChars]){
- struct symbolInfo *isNull;
- struct symbolInfo *prev;
- int listNumber = getHashKey(getName);
- isNull = symbolTable[listNumber];
- if((strcmp(symbolTable[listNumber]->name,getName) == 0)&& (strcmp(symbolTable[listNumber]->ID,getID)== 0),(strcmp(symbolTable[listNumber]->CGPA,getCGPA)== 0)){
- symbolTable[listNumber] = isNull->next;
- }
- else{
- while(isNull!=NULL){
- if((strcmp(isNull->name,getName) == 0) && (strcmp(isNull->ID,getID) == 0) &&(strcmp(isNull->CGPA,getCGPA) == 0)){
- prev->next=isNull->next;
- break;
- }
- prev=isNull;
- isNull=isNull->next;
- }
- }
- }
- int getHashKey(char value[numbOfChars]){
- int total = 0;
- int i;
- for(i=0; i<strlen(value); i++){
- total = total + value[i];
- }
- return total%numbOfList;
- }
- void menu(){
- int choice;
- while(1){
- printf("-------Menu------\n");
- printf("1. Insert\n");
- printf("2. Delete\n");
- printf("3. Show lists\n");
- printf("4. Exit\n");
- printf("-----------------\n\n");
- printf("Enter choice: ");
- scanf("%d", &choice);
- printf("\n");
- if(choice == 4){
- break;
- }
- else if (choice == 1){
- printf("Keep inserting. Enter 0 in both cases to stop\n\n");
- while(1){
- char setName[numbOfChars];
- char setID[numbOfChars];
- char setCGPA[numbOfChars];
- int hashKey;
- printf("Enter the name : ");
- scanf("%s", setName);
- printf("Enter ID : ");
- scanf("%s", setID);
- printf("Enter CGPA : ");
- scanf("%s", setCGPA);
- printf("\n");
- if((strcmp(setName, "0") == 0) && (strcmp(setID, "0") == 0)&& (strcmp(setCGPA, "0") == 0)) {
- break;
- }
- hashKey = getHashKey(setName);
- insert(setName, setID, setCGPA,hashKey);
- }
- }
- else if (choice == 2){
- char getName[numbOfChars];
- char getID[numbOfChars];
- char getCGPA[numbOfChars];
- printf("Enter the name for deleting: ");
- scanf("%s", getName);
- printf("Enter ID deleting: ");
- scanf("%s", getID);
- printf("Enter CGPA deleting: ");
- scanf("%s", getCGPA);
- printf("\n");
- deleteFromList(getName, getID, getCGPA);
- }
- else if (choice == 3){
- displayAll();
- }
- printf("\n\n");
- }
- }
- int main(){
- menu();
- printf("\n\n\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment