(Solved) : Ordered List Adt Implement Ordered List Adt Contains Struct Student Elements Id Int Name S Q41405902 . . .

Ordered List ADT Implement Ordered List ADT. It contains struct student as its elements. Id (int), name (string), email (stri

Ordered ListADT-Type Definitions #define STR_MAX 32 typedef struct student int id; char name [STR_MAX]; char email[STR_MAX];

Ordered ListADT - Function Declarations LIST* createList(int(*compare) (voidt pArgl, voidt pArg2)); LIST* destoryList(LIST* pOrdered ListADT - _search static bool _search(LIST* plist, NODE** pPre, NODE** ploc, void* pKey) { #define COMPARE (((*pList-MAIN #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include ordered ListADT.h int key = searchkeyOOutput #################### #################### NAME: yondon EMAIL: ydchung@korea.ac.kr # Insert dummy data # Search element

Ordered List ADT Implement Ordered List ADT. It contains struct student as its elements. Id (int), name (string), email (string) Operations create List – create a list destroyList – destroy a list insert – insert an element in ascending order of id Duplicate keys are not allowed. remove – erase an element with specific id retrieve – return an element with specific id size – return the number of elements isEmpty – return true if a list is empty iterate – traverses a list initlterator – initialize a position of an iterator printList – print all elements in list Ordered ListADT-Type Definitions #define STR_MAX 32 typedef struct student int id; char name [STR_MAX]; char email[STR_MAX]; } STUDENT; typedef struct node void* pData; struct node* next; } NODE; typedef struct int size; NODE* pos; NODE* head; NODE* rear; int(*compare) (void* pArgi, void* pArg2); } LIST; Ordered ListADT – Function Declarations LIST* createList(int(*compare) (voidt pArgl, voidt pArg2)); LIST* destoryList(LIST* pList); bool insert(LIST* pList, voidt pDataIn); bool remove (LIST* plist, void* pKey); bool retrieve(LIST* plist, voidt pkey, void** pDataOut); int size(LIST* pList); bool isEmpty (LIST* pList); bool iterate(LIST* plist, void** pDataOut); void initIterator (LIST* pList); void printList(LIST* Plist, void(*print) (void* pArg)); void printStudent(void* pArg); int cmpStudentId(void* pStudenti, void* pStudent2); static bool _insert(LIST* pList, NODE* pPre, voidt pDataIn); static void _delete(LIST* plist, NODE* pPre, NODE* pCur); static bool _search(LIST* pList, NODE** pPre, NODE** pCur, void* pKey); Ordered ListADT – _search static bool _search(LIST* plist, NODE** pPre, NODE** ploc, void* pKey) { #define COMPARE (((*pList->compare) (pkey, (*pLoc) ->pData))) #define COMPARE_LAST ((*pList->compare) (pkey, pList->rear->pData)) int result; *pPre = NULL; *pLoc = pList->head; if (pList->size == 0) return false; if (COMPARE_LAST > 0) *pPre = pList->rear; *pLoc = NULL; return false; while ((result = COMPARE) > 0) *pPre = *pLoc; *pLoc = (*pLoc)->next; if (result == 0) return true; else return false; MAIN #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include “ordered ListADT.h” int key = searchkeyOrder[i]; STUDENT* pStudent; STUDENT csDummy [] = if (retrieve(csStudents, (void*)&key, (void**)&pStudent)) {320001, “yangbong”, “beebee@korea.ac.kr” }, {320002, “hyoyong”, “utility@korea.ac.kr” }, {320003, “daegi”, “waiting@korea.ac.kr” }, {320004, “yondon”, “ydchung@korea.ac.kr” }, {320005, “minsoo”, “msdb@korea.ac.kr”} printf(“Student found (key: %d)n”, key); printStudent (pStudent); } else printf (“Search failed (key: %d)n”, key); int main() // Remove elements int erasekeyOrder [5] = { 320001, 320005, 320003, 320004, 320002 }; for (int i = 0; i < sizeof(erasekeyOrder) / sizeof(int); i++) int dummy Size = sizeof(csDummy) / sizeof(STUDENT); LIST *CS Students = createList(cmpStudentId); // Insert dummy data for (int i = 0; i < dummySize; i++) int key = erasekeyOrder[i]; STUDENT* student = (STUDENT*) malloc(sizeof(STUDENT)); student->id = csDummy[i].id; strcpy(student->name, csDummy[i].name); strcpy(student->email, csDummy[i].email); if (remove(cs Students, (void*)&key)) printf(“Erase successed (key: %d)n”, key); else printf(“Erase failed (key: %d)n”, key); printList(csStudents, printStudent); if (!insert(cs Students, (void*) student)) printf(“Insertion failedn”); // Iterate elements STUDENT* curStudent; while (iterate(cs Students, (void**)&curStudent)) printStudent (curStudent); initIterator (cs Students); // List empty check if (isEmpty(cs Students)) printf(“Emptyn”); else printf(“Not emptyn”); // Destory list destoryList(cs Students); return 0; // Search elements int searchkeyOrder[] = { 320001, 320003, 120001 }; for (int i = 0; i < sizeof(searchkeyOrder) / sizeof(int); i++) } Output #################### #################### NAME: yondon EMAIL: ydchung@korea.ac.kr # Insert dummy data # Search elements Student found (key: 320001) STUDENT ID: 320001 NAME: yangbong EMAIL: beebee @korea.ac.kr STUDENT ID: 320004 NAME: yondon EMAIL: ydchung@korea.ac.kr #################### STUDENT ID: 320005 NAME: minsoo EMAIL: msdb@korea.ac.kr # Iterate elements STUDENT ID: 320001 NAME: yangbong EMAIL: beebee @korea.ac.kr Student found (key: 320003) STUDENT ID: 320003 NAME: daegi EMAIL: waiting@korea.ac.kr Erase successed (key: 320004) STUDENT ID: 320002 NAME: hyoyong EMAIL: utility@korea.ac.kr ==================== Erase successed (key: 320005) STUDENT ID: 320002 NAME: hyoyong EMAIL: utility@korea.ac.kr STUDENT ID: 320002 NAME: hyoyong EMAIL: utility@korea.ac.kr ==================== Search failed (key: 120001) Erase successed (key: 320002) ========= STUDENT ID: 320003 NAME: daegi EMAIL: waiting @korea.ac.kr STUDENT ID: 320003 NAME: daegi EMAIL: waiting@korea.ac.kr #################### # Remove elements Erase successed (key: 320001) STUDENT ID: 320002 NAME: hyoyong EMAIL: utility@korea.ac.kr #################### # List empty check Empty 7140121 20 74=212…. STUDENT ID: 320004 NAME: yondon EMAIL: ydchung@korea.ac.kr STUDENT ID: 320004 NAME: yondon EMAIL: ydchung@korea.ac.kr ==================== STUDENT ID: 320005 NAME: minsoo EMAIL: msdb@korea.ac.kr STUDENT ID: 320003 NAME: daegi EMAIL: waiting@korea.ac.kr Erase successed (key: 320003) STUDENT ID: 320002 NAME: hyoyong EMAIL: utility@korea.ac.kr STUDENT ID: 320004 Show transcribed image text Ordered List ADT Implement Ordered List ADT. It contains struct student as its elements. Id (int), name (string), email (string) Operations create List – create a list destroyList – destroy a list insert – insert an element in ascending order of id Duplicate keys are not allowed. remove – erase an element with specific id retrieve – return an element with specific id size – return the number of elements isEmpty – return true if a list is empty iterate – traverses a list initlterator – initialize a position of an iterator printList – print all elements in list
Ordered ListADT-Type Definitions #define STR_MAX 32 typedef struct student int id; char name [STR_MAX]; char email[STR_MAX]; } STUDENT; typedef struct node void* pData; struct node* next; } NODE; typedef struct int size; NODE* pos; NODE* head; NODE* rear; int(*compare) (void* pArgi, void* pArg2); } LIST;
Ordered ListADT – Function Declarations LIST* createList(int(*compare) (voidt pArgl, voidt pArg2)); LIST* destoryList(LIST* pList); bool insert(LIST* pList, voidt pDataIn); bool remove (LIST* plist, void* pKey); bool retrieve(LIST* plist, voidt pkey, void** pDataOut); int size(LIST* pList); bool isEmpty (LIST* pList); bool iterate(LIST* plist, void** pDataOut); void initIterator (LIST* pList); void printList(LIST* Plist, void(*print) (void* pArg)); void printStudent(void* pArg); int cmpStudentId(void* pStudenti, void* pStudent2); static bool _insert(LIST* pList, NODE* pPre, voidt pDataIn); static void _delete(LIST* plist, NODE* pPre, NODE* pCur); static bool _search(LIST* pList, NODE** pPre, NODE** pCur, void* pKey);
Ordered ListADT – _search static bool _search(LIST* plist, NODE** pPre, NODE** ploc, void* pKey) { #define COMPARE (((*pList->compare) (pkey, (*pLoc) ->pData))) #define COMPARE_LAST ((*pList->compare) (pkey, pList->rear->pData)) int result; *pPre = NULL; *pLoc = pList->head; if (pList->size == 0) return false; if (COMPARE_LAST > 0) *pPre = pList->rear; *pLoc = NULL; return false; while ((result = COMPARE) > 0) *pPre = *pLoc; *pLoc = (*pLoc)->next; if (result == 0) return true; else return false;
MAIN #define _CRT_SECURE_NO_WARNINGS #include #include #include “ordered ListADT.h” int key = searchkeyOrder[i]; STUDENT* pStudent; STUDENT csDummy [] = if (retrieve(csStudents, (void*)&key, (void**)&pStudent)) {320001, “yangbong”, “beebee@korea.ac.kr” }, {320002, “hyoyong”, “utility@korea.ac.kr” }, {320003, “daegi”, “waiting@korea.ac.kr” }, {320004, “yondon”, “ydchung@korea.ac.kr” }, {320005, “minsoo”, “msdb@korea.ac.kr”} printf(“Student found (key: %d)n”, key); printStudent (pStudent); } else printf (“Search failed (key: %d)n”, key); int main() // Remove elements int erasekeyOrder [5] = { 320001, 320005, 320003, 320004, 320002 }; for (int i = 0; i name, csDummy[i].name); strcpy(student->email, csDummy[i].email); if (remove(cs Students, (void*)&key)) printf(“Erase successed (key: %d)n”, key); else printf(“Erase failed (key: %d)n”, key); printList(csStudents, printStudent); if (!insert(cs Students, (void*) student)) printf(“Insertion failedn”); // Iterate elements STUDENT* curStudent; while (iterate(cs Students, (void**)&curStudent)) printStudent (curStudent); initIterator (cs Students); // List empty check if (isEmpty(cs Students)) printf(“Emptyn”); else printf(“Not emptyn”); // Destory list destoryList(cs Students); return 0; // Search elements int searchkeyOrder[] = { 320001, 320003, 120001 }; for (int i = 0; i

Expert Answer


Answer to Ordered List ADT Implement Ordered List ADT. It contains struct student as its elements. Id (int), name (string), email …