Thread: Priority Queue Double Linked List

  1. #1
    Registered User
    Join Date
    Mar 2020

    Priority Queue Double Linked List

    You as a programmer asked to develop an application to distribute the cure, here is thedetails:
    1. Application must implement Priority Queue Double Linked List
    2. Input total patients and total cure available
    3. Input patient data (date of birth and full name) as much as total patients
    a. Format: dd mmmm yyyy - Full Name
    b. Example: 14 february 1980 - Ronald Rich

    4. Push all patient's data to Priority Queue Double Linked List. The older will beprioritized, check the date of birth.
    5. Pop/delete data as much as total cure
    6. View the result:
    a. If there is enough cure for patients show “All patients get the cure, N cure left”
    b. Otherwise, show “Need N more cure” and show patient’s data.

    7. Pop all data in Priority Queue Double Linked List

    Help Me To Completed This Snippet Below :

    struct data {
        int date, month, year;
        char name[100];
        struct data *next, *prev;
    }*head=NULL, *tail=NULL, *temp=NULL;
    void popHead();
    void popAll();
    void printAll();
    void addData();
    void priorityPush(int, int, int, char*);
    int getMonthNumber(char*);
    char* getMonthName(int);
    long getDateNumber(int, int, int);
    struct data *createNode(int, int, int, char*);
    long getDateNumber(int date, int month, int year) {
        return (long)(year*10000)+(month*100)+date;
    int getMonthNumber(char *month) {
        if(!strcmp(month, "january"))return 1;
        if(!strcmp(month, "february"))return 2;
        if(!strcmp(month, "march"))return 3;
        if(!strcmp(month, "april"))return 4;
        if(!strcmp(month, "may"))return 5;
        if(!strcmp(month, "june"))return 6;
        if(!strcmp(month, "july"))return 7;
        if(!strcmp(month, "august"))return 8;
        if(!strcmp(month, "september"))return 9;
        if(!strcmp(month, "october"))return 10;
        if(!strcmp(month, "november"))return 11;
        if(!strcmp(month, "december"))return 12;
    char* getMonthName(int month) {
        switch(month) {
            case 1: return "january";
            case 2: return "february";
            case 3: return "march";
            case 4: return "april";
            case 5: return "may";
            case 6: return "june";
            case 7: return "july";
            case 8: return "august";
            case 9: return "september";
            case 10: return "october";
            case 11: return "november";
            case 12: return "december";
    void popAll() {
    void printAll() {
        temp = head;
        while(temp != NULL) {
            printf("%d %s %d - %s\n", temp->date, getMonthName(temp->month), temp->year, temp->name);
            temp = temp->next;
    void addData() {
        int date, year;
        char month[100], name[100];
        scanf("%d %s %d - %[^\n]", &date, &month, &year, &name); getchar();
        priorityPush(date, getMonthNumber(month), year, name);
    struct data *createNode(int date, int month, int year, char *name) {
        // [1] INSERT YOUR CODE HERE
    void priorityPush(int date, int month, int year, char *name) {
        // [2] INSERT YOUR CODE HERE
    void popHead() {
        // [3] INSERT YOUR CODE HERE
    int main() {
        int totalPatients, totalCure;
        scanf("%d %d", &totalPatients, &totalCure); getchar();
        for(int i=0; i<totalPatients; i++)
        for(int i=0; i<totalCure; i++)
        if(totalPatients < totalCure || totalPatients == totalCure)
            printf("All patients get the cure, %d cure left\n", totalCure-totalPatients);
        else if(totalPatients > totalCure)
            printf("Need %d more cure\n", totalPatients-totalCure);
    Priority Queue Double Linked List-nomor4-jpg

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    The general idea is you make an attempt - more than just being a copy/paste service for your tutor.

    You make an attempt, then ask a question.
    We then help correct your mistakes and mis-understandings.

    You'll learn a lot more from it - which I assume is the point of you being on the course - to learn stuff.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. double ended priority queue
    By apatil65 in forum C Programming
    Replies: 8
    Last Post: 06-22-2013, 11:12 AM
  2. Linked List Queue
    By BretFlorida in forum C Programming
    Replies: 4
    Last Post: 04-16-2013, 10:19 AM
  3. Linked List Queue
    By BretFlorida in forum C Programming
    Replies: 9
    Last Post: 03-28-2013, 07:06 PM
  4. linked-list queue
    By the_winky_files in forum C Programming
    Replies: 17
    Last Post: 11-21-2005, 03:57 PM
  5. Linked List implementation of Queue
    By tdm2792 in forum C Programming
    Replies: 5
    Last Post: 11-04-2001, 04:04 PM

Tags for this Thread