Solve Sorting Technique Problem with 4 Elementary Sorts

  • Thread starter shayanahmad
  • Start date
  • Tags
    Sorting
In order to do that, you need to implement each of those four sorting algorithms. You can find information about how to do that by searching online or in your class materials. Once you have the algorithms implemented, you can use them to sort the patient data by age and patient ID.
  • #1
shayanahmad
2
0
Hello I'm having problem in solving this question with c/c++ code , please help me ?


An eccentric doctor visits his patients in order of decreasing age. Patients entering the waiting list specify not only their names but also their ages. Each time the doctor wants to visit a patient, the oldest is selected and removed from the list (so children may have to wait a very long time). Write a program, based on elementary sorting techniques to sort this list on first on Age and then on Patient ID, which this doctor can use.


Before
PatientID Name Age
P102 Arif Taj Mairza 50
P203 Sadar Khan 65
P546 Afsheen Bano 34
P605 Kai Whong 45
P340 Hanah Duong 23
P391 Usman Habib 65
P200 Alina Shah 34

After
PatientID Name Age
P203 Sadar Khan 65
P391 Usman Habib 65
P102 Arif Taj Mairza 50
P605 Kai Whong 45
P200 Alina Shah 34
P546 Afsheen Bano 34
P340 Hanah Duong 23



Solve this problem by applying four different elementary sorting techniques that are

a) Selection sort
b) Bubble sort
c) Insertion sort
d) Shell sort
 
Physics news on Phys.org
  • #2
Since this is appears to be homework, you need to show some idea of what you've tried so far. The different sort algorithms can be found doing a web search if they aren't already describe in some form from your class.

I assume the data is in a text file. What have you learned about reading lines and parsing (separating lines into sub-fields) so far in your class?
 
  • #3
i have done this so far , now please guide me how to sort this with respect to patient id and age

#include <iostream>
using namespace std;

typedef struct
{
char name[100];
int patientno;
int age;
} Input;

int main (int argc, char *argv[],int pno)
{
int i;
int NUMBER_OF_PATIENTS;

cout<<"Enter number of patients:";
cin>>NUMBER_OF_PATIENTS;

Input input[NUMBER_OF_PATIENTS];
int patientno;

for (i=0; i < NUMBER_OF_PATIENTS; ++i)
{
cout<<"Enter patient no: ";
cin>>input.patientno;

cout<<"Enter patient name:";
cin>>input.name;

cout<<"Enter patient age:";
cin>>input.age;
}
for (i=0; i<NUMBER_OF_PATIENTS; ++i)
{
cout<<"P"<<input.patientno<<" "<<input.name<<" "<<input.age<<endl;
}
system("pause");
return 0;

}
 
  • #4
Rather that have a user input data each time you run the program, I think it would be better to store the data into a text file (you can use notepad or any text editor to do this). Then have your program read in the entire file, parse for lines and fields, or read the file one line at a time (several functions to do this) and parse each line for fields.
 
Last edited:
  • #5
In addition to what rcgldr already said, your code is doing nothing more than filling the input array with patient data, and then displaying the data. You aren't sorting the data by any of the four methods you're supposed to use.
 

Related to Solve Sorting Technique Problem with 4 Elementary Sorts

1. What are the four elementary sorts used in solving sorting technique problems?

The four elementary sorts used in solving sorting technique problems are bubble sort, selection sort, insertion sort, and shell sort.

2. How does bubble sort work in solving sorting technique problems?

Bubble sort works by comparing adjacent elements in a list and swapping them if they are not in the correct order. This process is repeated until the list is sorted.

3. What is the time complexity of selection sort in solving sorting technique problems?

The time complexity of selection sort is O(n^2), as it involves nested loops to iterate through the list and find the minimum element.

4. How does insertion sort compare to other sorting techniques in terms of efficiency?

Insertion sort is considered to be more efficient than bubble and selection sorts, but less efficient than more advanced techniques such as merge sort or quick sort. Its time complexity is O(n^2) on average.

5. What is the main advantage of using shell sort in solving sorting technique problems?

The main advantage of using shell sort is that it has a better time complexity than other elementary sorts, with an average time complexity of O(nlogn). It also has the added benefit of being an in-place sorting algorithm, meaning it does not require extra memory space to sort the list.

Back
Top