Question

Please answer in C A doubly linked list is a list in which each entry contains...

Please answer in C

A doubly linked list is a list in which each entry contains a pointer to the preceding entry in the list as well as a pointer to the next entry in the list. Define the appropriate structure for the doubly linked list. Write a user space program that implements a doubly linked list and prints out the elements of the list. Develop insert_entry() and remove_entry() functions for this list. The link list should store information on runners at a track meet that are on lanes 1 through 8. Information such as bib number, name, school, qualifier time, etc. must be stored.

Homework Answers

Answer #1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct runner {
        int bib;
        char name[100];
};

struct node
{
        struct runner data;
        struct node *prev;
        struct node *next;
};
struct node *head;


void insert_entry(struct runner item) {
        struct node *ptr, *temp;
        ptr = (struct node *) malloc(sizeof(struct node));
        if (ptr == NULL)
                return;

        ptr->data = item;
        if (head == NULL)
        {
                ptr->next = NULL;
                ptr->prev = NULL;
                head = ptr;
        }
        else
        {
                temp = head;
                while (temp->next != NULL)
                {
                        temp = temp->next;
                }
                temp->next = ptr;
                ptr ->prev = temp;
                ptr->next = NULL;
        }


}


void remove_entry() {
        struct node *ptr;
        if (head == NULL)
                return;

        if (head->next == NULL)
        {
                head = NULL;
                free(head);
        }
        else
        {
                ptr = head;
                if (ptr->next != NULL)
                {
                        ptr = ptr -> next;
                }
                ptr -> prev -> next = NULL;
                free(ptr);
        }
}

void display() {
        struct node *ptr;
        printf("...Runners...\n\n");
        ptr = head;
        while (ptr != NULL)
        {
                printf("BIB Number: %d\t Name: %s\n", ptr->data.bib,ptr->data.name);
                ptr = ptr->next;
        }
}

int main ()  {

        struct runner a;
        a.bib = 1;
        strcpy(a.name,"Michael");
        insert_entry(a);

        a.bib = 2;
        strcpy(a.name,"Ramos");
        insert_entry(a);
        a.bib = 3;
        strcpy(a.name,"Messi");
        insert_entry(a);
        a.bib = 4;
        strcpy(a.name,"Benzema");
        insert_entry(a);
        a.bib = 5;
        strcpy(a.name,"Cristiano");
        insert_entry(a);
        a.bib = 6;
        strcpy(a.name,"Ronaldhino");
        insert_entry(a);
        a.bib = 7;
        strcpy(a.name,"Ambape");
        insert_entry(a);
        a.bib = 8;
        strcpy(a.name,"Neymar");
        insert_entry(a);

        display();
        return 0;
}

OUTPUT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question....
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question. Thank you! Here’s the contents of a file called example.cpp: // example.cpp #include "LinkedList.h" #include <iostream> #include <string> using namespace std; int main() { cout << "Please enter some words (ctrl-d to stop):\n"; LinkedList lst; int count = 0; string s; while (cin >> s) { count++; lst.add(remove_non_letters(s)); } // while cout << "\n" << count << " total words read in\n"; cout <<...
read Seasons of Love chapter:measuring a child's life after suicide. please answer the questions : reflect...
read Seasons of Love chapter:measuring a child's life after suicide. please answer the questions : reflect on what happens to the families when there is a suicide in the family, based on the Seasons of Love chapter...how should people be told? What details are best left unshared? below is the story These theories may have a certain face-validity, but they often neglect environmental or contextual factors that are innate to answering the question of “why” a person might engage in...
Review the Robatelli's Pizzeria Case Study. Develop another internal controls system, but this time, in the...
Review the Robatelli's Pizzeria Case Study. Develop another internal controls system, but this time, in the purchases and fixed assets business areas. Prepare a 12- to 16-slide presentation describing the purchases and fixed assets business areas. Be sure to incorporate speaker notes as well as appropriate visuals, graphics, fonts, etc. Include any associated risk in these areas. Describe specific internal controls that include authorization of transactions, segregation of duties, adequate records and documentation, security of assets, and independent checks and...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT