SlideShare a Scribd company logo
1 of 5
Download to read offline
/*
Task 1:
This program sorts an array of EMPLOYEE structures using the insertion sort algorithm.
There are two sort functions:
void insertionSortA(EMPLOYEE list[], EMPLOYEE *pLast); // sort ascending order by class
ID
void insertionSortB(EMPLOYEE list[], EMPLOYEE *pLast); // sort ascending order by name
void insertionSortC(EMPLOYEE list[], EMPLOYEE *pLast); // sort descending order by year
REQUIREMENTS (Use C Language) :
1. Replace the three sorting functions with one generic sort:
void insertionSort(EMPLOYEE list[], EMPLOYEE *pLast, int compare(void *, void *));
2. Define a compare function to be used as a parameter for the first call of the generic sort:
int compareIds(void *p1, void *p2);
3. Define a compare function to be used as a parameter for the second call of the generic sort:
int compareNames(void *p1, void *p2);
4. Define a compare function to be used as a parameter for the third call of the generic sort:
int compareYears(void *p1, void *p2);
5. Replace the calls for the given three sort functions with calls for the generic sort function
6. Run the program.
7. Save the output as a comment at the end of the source file.
*~*/
#include
#include
#define NUM_EMP 500
typedef struct
{
char id[16];
char name[64];
int year;
} EMPLOYEE;
void insertionSortA(EMPLOYEE list[], EMPLOYEE *pLast);
void insertionSortB(EMPLOYEE list[], EMPLOYEE *pLast);
void insertionSortC(EMPLOYEE list[], EMPLOYEE *pLast);
void printList(EMPLOYEE list[], EMPLOYEE *pLast, char *description);
int main (void)
{
EMPLOYEE*pLast;
EMPLOYEE empList[NUM_EMP] =
{
{"9182", "John", 2011},
{"7364", "Ann", 2007},
{"1829", "Linda", 2022},
{"3647", "Jack", 1997},
{"8245", "Vince", 1995},
{"6473", "Jane", 1999},
{"8209", "Megan", 2003},
{"3637", "Jim", 2013},
{"6443", "Mary", 1998},
{"8809", "Tom", 2019},
{"3633", "Bob", 2021}
};
int numberOfEmployees = 11;
pLast = empList + numberOfEmployees - 1;
printList(empList, pLast, "Unsorted");
// first sort
insertionSortA(empList, pLast);
printList(empList, pLast, "Sorted by ID");
// second sort
insertionSortB(empList, pLast);
printList(empList, pLast, "Sorted by name");
// third sort
insertionSortC(empList, pLast);
printList(empList, pLast, "Sorted by year (descending)");
return 0;
}
/*~*~*~*~*~*~
Sort list using Insertion Sort.
Sort by ascending order of id
Pre list[] must contain at least one element
size is index to last element in list
Post list has been rearranged.
*~*/
void insertionSortA(EMPLOYEE list[], EMPLOYEE *pLast)
{
EMPLOYEE temp;
EMPLOYEE *pCurr;
EMPLOYEE *pWalk;
for (pCurr = list + 1; pCurr <= pLast; pCurr++)
{
temp = *pCurr;
pWalk = pCurr - 1;
while (pWalk >= list && strcmp(temp.id, pWalk->id) < 0)
{
*(pWalk + 1) = *pWalk;
pWalk--;
}
*(pWalk + 1) = temp;
}
}
/*~*~*~*~*~*~
Sort list using Insertion Sort.
Sort by ascending order of number of name.
Pre list[] must contain at least one element
size is index to last element in list
Post list has been rearranged
*~*/
void insertionSortB(EMPLOYEE list[], EMPLOYEE *pLast)
{
EMPLOYEE temp;
EMPLOYEE *pCurr;
EMPLOYEE *pWalk;
for (pCurr = list + 1; pCurr <= pLast; pCurr++)
{
temp = *pCurr;
pWalk = pCurr - 1;
while (pWalk >= list && strcmp(temp.name, pWalk->name) < 0 )
{
*(pWalk + 1) = *pWalk;
pWalk--;
}
*(pWalk + 1) = temp;
}
}
/*~*~*~*~*~*~
Sort list using Insertion Sort.
Sort by descending order of year.
Pre list[] must contain at least one element
size is index to last element in list
Post list has been rearranged
*~*/
void insertionSortC(EMPLOYEE list[], EMPLOYEE *pLast)
{
EMPLOYEE temp;
EMPLOYEE *pCurr;
EMPLOYEE *pWalk;
for (pCurr = list + 1; pCurr <= pLast; pCurr++)
{
temp = *pCurr;
pWalk = pCurr - 1;
while (pWalk >= list && temp.year > pWalk->year )
{
*(pWalk + 1) = *pWalk;
pWalk--;
}
*(pWalk + 1) = temp;
}
}
/*~*~*~*~*~*~
Print list prints.
Pre list[] must contain at least one element
size is index to last element in list
Post list has been rearranged
*~*/
void printList(EMPLOYEE list[], EMPLOYEE *pLast, char *description)
{
EMPLOYEE *pCurr;
printf("%s: n", description);
for (pCurr = list; pCurr <= pLast; pCurr++)
{
printf("%-5s %-5s %4d n", pCurr->id, pCurr->name, pCurr->year);
}
printf("n");
}
/* Save the output below
*/

More Related Content

Similar to Task 1This program sorts an array of EMPLOYEE structures usin.pdf

Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Calvin Cheng
 
create a stack trace for this code I have provided the starter code as.pdf
create a stack trace for this code I have provided the starter code as.pdfcreate a stack trace for this code I have provided the starter code as.pdf
create a stack trace for this code I have provided the starter code as.pdfjyotartenterprises
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfflashfashioncasualwe
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfcontact41
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfarihantelehyb
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfangelfragranc
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)mailmerk
 
The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31Mahmoud Samir Fayed
 
operator overloading
operator overloadingoperator overloading
operator overloadingNishant Joshi
 

Similar to Task 1This program sorts an array of EMPLOYEE structures usin.pdf (20)

Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)
 
create a stack trace for this code I have provided the starter code as.pdf
create a stack trace for this code I have provided the starter code as.pdfcreate a stack trace for this code I have provided the starter code as.pdf
create a stack trace for this code I have provided the starter code as.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdf
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
 
The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31
 
operator overloading
operator overloadingoperator overloading
operator overloading
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 

More from allisontraders

Suppose you are designing a randomized intervention trial of a socia.pdf
Suppose you are designing a randomized intervention trial of a socia.pdfSuppose you are designing a randomized intervention trial of a socia.pdf
Suppose you are designing a randomized intervention trial of a socia.pdfallisontraders
 
Suppose the nominal interest rate for both 2020 and 2021 is zero and.pdf
Suppose the nominal interest rate for both 2020 and 2021 is zero and.pdfSuppose the nominal interest rate for both 2020 and 2021 is zero and.pdf
Suppose the nominal interest rate for both 2020 and 2021 is zero and.pdfallisontraders
 
Suppose the U.S. president wants to estimate the proportion of the p.pdf
Suppose the U.S. president wants to estimate the proportion of the p.pdfSuppose the U.S. president wants to estimate the proportion of the p.pdf
Suppose the U.S. president wants to estimate the proportion of the p.pdfallisontraders
 
Suppose we have a database for an university.The requirements are .pdf
Suppose we have a database for an university.The requirements are .pdfSuppose we have a database for an university.The requirements are .pdf
Suppose we have a database for an university.The requirements are .pdfallisontraders
 
Suppose we have a database for an university. The requirements are a.pdf
Suppose we have a database for an university. The requirements are a.pdfSuppose we have a database for an university. The requirements are a.pdf
Suppose we have a database for an university. The requirements are a.pdfallisontraders
 
TCPIP Client Server program exampleHere is a simple example of .pdf
TCPIP Client Server program exampleHere is a simple example of .pdfTCPIP Client Server program exampleHere is a simple example of .pdf
TCPIP Client Server program exampleHere is a simple example of .pdfallisontraders
 
Tanni Tamaki and Gerald Malada are a married couple and they equally.pdf
Tanni Tamaki and Gerald Malada are a married couple and they equally.pdfTanni Tamaki and Gerald Malada are a married couple and they equally.pdf
Tanni Tamaki and Gerald Malada are a married couple and they equally.pdfallisontraders
 
Technology is in many ways an enabler in shaping and defining our li.pdf
Technology is in many ways an enabler in shaping and defining our li.pdfTechnology is in many ways an enabler in shaping and defining our li.pdf
Technology is in many ways an enabler in shaping and defining our li.pdfallisontraders
 
Ted talk To overcome challenges, stop comparing yourself to others .pdf
Ted talk To overcome challenges, stop comparing yourself to others .pdfTed talk To overcome challenges, stop comparing yourself to others .pdf
Ted talk To overcome challenges, stop comparing yourself to others .pdfallisontraders
 
Teamwork that you have accomplished so far; What you have learned fr.pdf
Teamwork that you have accomplished so far; What you have learned fr.pdfTeamwork that you have accomplished so far; What you have learned fr.pdf
Teamwork that you have accomplished so far; What you have learned fr.pdfallisontraders
 
Task II Read the following case stud thoroughly, then answer the fo.pdf
Task II Read the following case stud thoroughly, then answer the fo.pdfTask II Read the following case stud thoroughly, then answer the fo.pdf
Task II Read the following case stud thoroughly, then answer the fo.pdfallisontraders
 
Task required to perform You will develop a Social Media Marketing .pdf
Task required to perform You will develop a Social Media Marketing .pdfTask required to perform You will develop a Social Media Marketing .pdf
Task required to perform You will develop a Social Media Marketing .pdfallisontraders
 
TASK The Financial Controller is not attending the next Board meeti.pdf
TASK The Financial Controller is not attending the next Board meeti.pdfTASK The Financial Controller is not attending the next Board meeti.pdf
TASK The Financial Controller is not attending the next Board meeti.pdfallisontraders
 
Talias Tea Shoppes ha llegado a un acuerdo con Consumer Rail Corp. .pdf
Talias Tea Shoppes ha llegado a un acuerdo con Consumer Rail Corp. .pdfTalias Tea Shoppes ha llegado a un acuerdo con Consumer Rail Corp. .pdf
Talias Tea Shoppes ha llegado a un acuerdo con Consumer Rail Corp. .pdfallisontraders
 
Suppose that you wanted to create a crop plant that has cabbage leav.pdf
Suppose that you wanted to create a crop plant that has cabbage leav.pdfSuppose that you wanted to create a crop plant that has cabbage leav.pdf
Suppose that you wanted to create a crop plant that has cabbage leav.pdfallisontraders
 
Take any successful, high performing organization.Elaborate the vi.pdf
Take any successful, high performing organization.Elaborate the vi.pdfTake any successful, high performing organization.Elaborate the vi.pdf
Take any successful, high performing organization.Elaborate the vi.pdfallisontraders
 
Talaromyces marneffei1. What is its genus species and phyla2. I.pdf
Talaromyces marneffei1. What is its genus species and phyla2. I.pdfTalaromyces marneffei1. What is its genus species and phyla2. I.pdf
Talaromyces marneffei1. What is its genus species and phyla2. I.pdfallisontraders
 
Tabla 7.14 Cincuenta a�os de supervivencia para hombres despu�s de .pdf
Tabla 7.14 Cincuenta a�os de supervivencia para hombres despu�s de .pdfTabla 7.14 Cincuenta a�os de supervivencia para hombres despu�s de .pdf
Tabla 7.14 Cincuenta a�os de supervivencia para hombres despu�s de .pdfallisontraders
 
T-tests are hypothesis tests for mean differences. They are used to .pdf
T-tests are hypothesis tests for mean differences. They are used to .pdfT-tests are hypothesis tests for mean differences. They are used to .pdf
T-tests are hypothesis tests for mean differences. They are used to .pdfallisontraders
 

More from allisontraders (20)

Suppose you are designing a randomized intervention trial of a socia.pdf
Suppose you are designing a randomized intervention trial of a socia.pdfSuppose you are designing a randomized intervention trial of a socia.pdf
Suppose you are designing a randomized intervention trial of a socia.pdf
 
Suppose the nominal interest rate for both 2020 and 2021 is zero and.pdf
Suppose the nominal interest rate for both 2020 and 2021 is zero and.pdfSuppose the nominal interest rate for both 2020 and 2021 is zero and.pdf
Suppose the nominal interest rate for both 2020 and 2021 is zero and.pdf
 
Suppose the U.S. president wants to estimate the proportion of the p.pdf
Suppose the U.S. president wants to estimate the proportion of the p.pdfSuppose the U.S. president wants to estimate the proportion of the p.pdf
Suppose the U.S. president wants to estimate the proportion of the p.pdf
 
Suppose we have a database for an university.The requirements are .pdf
Suppose we have a database for an university.The requirements are .pdfSuppose we have a database for an university.The requirements are .pdf
Suppose we have a database for an university.The requirements are .pdf
 
Suppose we have a database for an university. The requirements are a.pdf
Suppose we have a database for an university. The requirements are a.pdfSuppose we have a database for an university. The requirements are a.pdf
Suppose we have a database for an university. The requirements are a.pdf
 
TCPIP Client Server program exampleHere is a simple example of .pdf
TCPIP Client Server program exampleHere is a simple example of .pdfTCPIP Client Server program exampleHere is a simple example of .pdf
TCPIP Client Server program exampleHere is a simple example of .pdf
 
Tanni Tamaki and Gerald Malada are a married couple and they equally.pdf
Tanni Tamaki and Gerald Malada are a married couple and they equally.pdfTanni Tamaki and Gerald Malada are a married couple and they equally.pdf
Tanni Tamaki and Gerald Malada are a married couple and they equally.pdf
 
Technology is in many ways an enabler in shaping and defining our li.pdf
Technology is in many ways an enabler in shaping and defining our li.pdfTechnology is in many ways an enabler in shaping and defining our li.pdf
Technology is in many ways an enabler in shaping and defining our li.pdf
 
Ted talk To overcome challenges, stop comparing yourself to others .pdf
Ted talk To overcome challenges, stop comparing yourself to others .pdfTed talk To overcome challenges, stop comparing yourself to others .pdf
Ted talk To overcome challenges, stop comparing yourself to others .pdf
 
Teamwork that you have accomplished so far; What you have learned fr.pdf
Teamwork that you have accomplished so far; What you have learned fr.pdfTeamwork that you have accomplished so far; What you have learned fr.pdf
Teamwork that you have accomplished so far; What you have learned fr.pdf
 
Task II Read the following case stud thoroughly, then answer the fo.pdf
Task II Read the following case stud thoroughly, then answer the fo.pdfTask II Read the following case stud thoroughly, then answer the fo.pdf
Task II Read the following case stud thoroughly, then answer the fo.pdf
 
Task required to perform You will develop a Social Media Marketing .pdf
Task required to perform You will develop a Social Media Marketing .pdfTask required to perform You will develop a Social Media Marketing .pdf
Task required to perform You will develop a Social Media Marketing .pdf
 
TASK The Financial Controller is not attending the next Board meeti.pdf
TASK The Financial Controller is not attending the next Board meeti.pdfTASK The Financial Controller is not attending the next Board meeti.pdf
TASK The Financial Controller is not attending the next Board meeti.pdf
 
Talias Tea Shoppes ha llegado a un acuerdo con Consumer Rail Corp. .pdf
Talias Tea Shoppes ha llegado a un acuerdo con Consumer Rail Corp. .pdfTalias Tea Shoppes ha llegado a un acuerdo con Consumer Rail Corp. .pdf
Talias Tea Shoppes ha llegado a un acuerdo con Consumer Rail Corp. .pdf
 
Suppose that you wanted to create a crop plant that has cabbage leav.pdf
Suppose that you wanted to create a crop plant that has cabbage leav.pdfSuppose that you wanted to create a crop plant that has cabbage leav.pdf
Suppose that you wanted to create a crop plant that has cabbage leav.pdf
 
Take any successful, high performing organization.Elaborate the vi.pdf
Take any successful, high performing organization.Elaborate the vi.pdfTake any successful, high performing organization.Elaborate the vi.pdf
Take any successful, high performing organization.Elaborate the vi.pdf
 
Talaromyces marneffei1. What is its genus species and phyla2. I.pdf
Talaromyces marneffei1. What is its genus species and phyla2. I.pdfTalaromyces marneffei1. What is its genus species and phyla2. I.pdf
Talaromyces marneffei1. What is its genus species and phyla2. I.pdf
 
Tabla 7.14 Cincuenta a�os de supervivencia para hombres despu�s de .pdf
Tabla 7.14 Cincuenta a�os de supervivencia para hombres despu�s de .pdfTabla 7.14 Cincuenta a�os de supervivencia para hombres despu�s de .pdf
Tabla 7.14 Cincuenta a�os de supervivencia para hombres despu�s de .pdf
 
T-tests are hypothesis tests for mean differences. They are used to .pdf
T-tests are hypothesis tests for mean differences. They are used to .pdfT-tests are hypothesis tests for mean differences. They are used to .pdf
T-tests are hypothesis tests for mean differences. They are used to .pdf
 
t=SMMM.pdf
t=SMMM.pdft=SMMM.pdf
t=SMMM.pdf
 

Recently uploaded

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 

Recently uploaded (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

Task 1This program sorts an array of EMPLOYEE structures usin.pdf

  • 1. /* Task 1: This program sorts an array of EMPLOYEE structures using the insertion sort algorithm. There are two sort functions: void insertionSortA(EMPLOYEE list[], EMPLOYEE *pLast); // sort ascending order by class ID void insertionSortB(EMPLOYEE list[], EMPLOYEE *pLast); // sort ascending order by name void insertionSortC(EMPLOYEE list[], EMPLOYEE *pLast); // sort descending order by year REQUIREMENTS (Use C Language) : 1. Replace the three sorting functions with one generic sort: void insertionSort(EMPLOYEE list[], EMPLOYEE *pLast, int compare(void *, void *)); 2. Define a compare function to be used as a parameter for the first call of the generic sort: int compareIds(void *p1, void *p2); 3. Define a compare function to be used as a parameter for the second call of the generic sort: int compareNames(void *p1, void *p2); 4. Define a compare function to be used as a parameter for the third call of the generic sort: int compareYears(void *p1, void *p2); 5. Replace the calls for the given three sort functions with calls for the generic sort function 6. Run the program. 7. Save the output as a comment at the end of the source file. *~*/ #include #include #define NUM_EMP 500 typedef struct { char id[16]; char name[64]; int year; } EMPLOYEE; void insertionSortA(EMPLOYEE list[], EMPLOYEE *pLast); void insertionSortB(EMPLOYEE list[], EMPLOYEE *pLast); void insertionSortC(EMPLOYEE list[], EMPLOYEE *pLast); void printList(EMPLOYEE list[], EMPLOYEE *pLast, char *description); int main (void)
  • 2. { EMPLOYEE*pLast; EMPLOYEE empList[NUM_EMP] = { {"9182", "John", 2011}, {"7364", "Ann", 2007}, {"1829", "Linda", 2022}, {"3647", "Jack", 1997}, {"8245", "Vince", 1995}, {"6473", "Jane", 1999}, {"8209", "Megan", 2003}, {"3637", "Jim", 2013}, {"6443", "Mary", 1998}, {"8809", "Tom", 2019}, {"3633", "Bob", 2021} }; int numberOfEmployees = 11; pLast = empList + numberOfEmployees - 1; printList(empList, pLast, "Unsorted"); // first sort insertionSortA(empList, pLast); printList(empList, pLast, "Sorted by ID"); // second sort insertionSortB(empList, pLast); printList(empList, pLast, "Sorted by name"); // third sort insertionSortC(empList, pLast); printList(empList, pLast, "Sorted by year (descending)"); return 0; } /*~*~*~*~*~*~ Sort list using Insertion Sort. Sort by ascending order of id Pre list[] must contain at least one element size is index to last element in list Post list has been rearranged.
  • 3. *~*/ void insertionSortA(EMPLOYEE list[], EMPLOYEE *pLast) { EMPLOYEE temp; EMPLOYEE *pCurr; EMPLOYEE *pWalk; for (pCurr = list + 1; pCurr <= pLast; pCurr++) { temp = *pCurr; pWalk = pCurr - 1; while (pWalk >= list && strcmp(temp.id, pWalk->id) < 0) { *(pWalk + 1) = *pWalk; pWalk--; } *(pWalk + 1) = temp; } } /*~*~*~*~*~*~ Sort list using Insertion Sort. Sort by ascending order of number of name. Pre list[] must contain at least one element size is index to last element in list Post list has been rearranged *~*/ void insertionSortB(EMPLOYEE list[], EMPLOYEE *pLast) { EMPLOYEE temp; EMPLOYEE *pCurr; EMPLOYEE *pWalk; for (pCurr = list + 1; pCurr <= pLast; pCurr++) { temp = *pCurr; pWalk = pCurr - 1; while (pWalk >= list && strcmp(temp.name, pWalk->name) < 0 ) {
  • 4. *(pWalk + 1) = *pWalk; pWalk--; } *(pWalk + 1) = temp; } } /*~*~*~*~*~*~ Sort list using Insertion Sort. Sort by descending order of year. Pre list[] must contain at least one element size is index to last element in list Post list has been rearranged *~*/ void insertionSortC(EMPLOYEE list[], EMPLOYEE *pLast) { EMPLOYEE temp; EMPLOYEE *pCurr; EMPLOYEE *pWalk; for (pCurr = list + 1; pCurr <= pLast; pCurr++) { temp = *pCurr; pWalk = pCurr - 1; while (pWalk >= list && temp.year > pWalk->year ) { *(pWalk + 1) = *pWalk; pWalk--; } *(pWalk + 1) = temp; } } /*~*~*~*~*~*~ Print list prints. Pre list[] must contain at least one element size is index to last element in list Post list has been rearranged *~*/
  • 5. void printList(EMPLOYEE list[], EMPLOYEE *pLast, char *description) { EMPLOYEE *pCurr; printf("%s: n", description); for (pCurr = list; pCurr <= pLast; pCurr++) { printf("%-5s %-5s %4d n", pCurr->id, pCurr->name, pCurr->year); } printf("n"); } /* Save the output below */