ent ID numbers and their corresponding GPAs in a structure. ID numbers should be 8 digits. (Ex. 11926743) and GPA should be (0.0, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0) Add students Remove students Display the list of students Start of code:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C LANGUAGE ONLY. ANSWER ASAP.

Using the program provided below:

Add the following features that are listed below to the provided program:

  • Store student ID numbers and their corresponding GPAs in a structure. ID numbers should be 8 digits. (Ex. 11926743) and GPA should be (0.0, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0)
  • Add students
  • Remove students
  • Display the list of students

Start of code:

FILE NAME: linked_lists.h

#ifndef LINKED_LISTS_H
#define LINKED_LISTS_H

struct node {
    int data;
    struct node* next;
};

void insertAtBeginning(struct node** head, int data);
void insertAtEnd(struct node** head, int data);
void insertAfter(struct node* prev_node, int data);
void deleteNode(struct node** head, int key);
void swapNodes(struct node** head, int x, int y);
void printList(struct node* head);

#endif

FILE NAME: linked_lists.c

#include <stdio.h>
#include <stdlib.h>
#include "linked_lists.h"

void insertAtBeginning(struct node** head, int data) {
    struct node* new_node = (struct node*)malloc(sizeof(struct node));
    new_node->data = data;
    new_node->next = *head;
    *head = new_node;
}

void insertAtEnd(struct node** head, int data) {
    struct node* new_node = (struct node*)malloc(sizeof(struct node));
    struct node* last = *head;
    new_node->data = data;
    new_node->next = NULL;
    if (*head == NULL) {
        *head = new_node;
        return;
    }
    while (last->next != NULL)
        last = last->next;
    last->next = new_node;
    return;
}

void insertAfter(struct node* prev_node, int data) {
    if (prev_node == NULL) {
        printf("The given previous node cannot be NULL\n");
        return;
    }
    struct node* new_node = (struct node*)malloc(sizeof(struct node));
    new_node->data = data;
    new_node->next = prev_node->next;
    prev_node->next = new_node;
}

void deleteNode(struct node** head, int key) {
    struct node* temp = *head, *prev;
    if (temp != NULL && temp->data == key) {
        *head = temp->next;
        free(temp);
        return;
    }
    while (temp != NULL && temp->data != key) {
        prev = temp;
        temp = temp->next;
    }
    if (temp == NULL) return;
    prev->next = temp->next;
    free(temp);
}

void swapNodes(struct node** head, int x, int y) {
    if (x == y) return;
    struct node *prevX = NULL, *currX = *head;
    while (currX && currX->data != x) {
        prevX = currX;
        currX = currX->next;
    }
    struct node *prevY = NULL, *currY = *head;
    while (currY && currY->data != y) {
        prevY = currY;
        currY = currY->next;
    }
    if (currX == NULL || currY == NULL) return;
    if (prevX != NULL) prevX->next = currY;
    else *head = currY;
    if (prevY != NULL) prevY->next = currX;
    else *head = currX;
    struct node* temp = currY->next;
    currY->next = currX->next;
    currX->next = temp;
}

void printList(struct node* head) {
    while (head != NULL) {
        printf("%d ", head->data);
        head = head->next;
    }
    printf("\n");
}


int main() {
    struct node* head = NULL;
    insertAtEnd(&head, 1);
    insertAtEnd(&head, 2);
    insertAtBeginning(&head, 3);
    insertAfter(head->next, 4);
    printf("Linked List: ");
    printList(head);
    deleteNode(&head, 3);
    printf("Linked List after deletion of 3: ");
    printList(head);
    swapNodes(&head, 1, 2);
    printf("Linked List after swapping 1 and 2: ");
    printList(head);
    return 0;
}

 

THANK YOU!

SAWNI
#ifndef LINKED_LISTS_H
#define LINKED_LISTS_H
4 struct node {
int data;
5
6
7
8
9
void insertAtBeginning(struct node** head, int data);
10 void insertAtEnd(struct node** head, int data);
11 void insertAfter(struct
node* prev_node, int data);
12 void deleteNode (struct node** head, int key);
13 void swapNodes (struct node** head, int x, int y);
14 void printList(struct node* head);
15
16
#endif
struct node* next;
};
Transcribed Image Text:SAWNI #ifndef LINKED_LISTS_H #define LINKED_LISTS_H 4 struct node { int data; 5 6 7 8 9 void insertAtBeginning(struct node** head, int data); 10 void insertAtEnd(struct node** head, int data); 11 void insertAfter(struct node* prev_node, int data); 12 void deleteNode (struct node** head, int key); 13 void swapNodes (struct node** head, int x, int y); 14 void printList(struct node* head); 15 16 #endif struct node* next; };
#include <stdio.h>
#include <stdlib.h>
#include "linked_lists.h"
void insertAtBeginning(struct node** head, int data) {
struct node* new_node = (struct node*)malloc(sizeof(struct node));
new_node->data = data;
new_node->next = *head;
*head = new_node;
}
void insertAtEnd(struct node** head, int data) {
struct node* new_node = (struct node*)malloc(sizeof(struct node));
struct node* last = *head;
new_node->data = data;
new_node->next = NULL;
if (*head = NULL) {
*head = new_node;
return;
}
void insertAfter (struct node* prev_node, int data) {
if (prev_node == NULL) {
}
}
while (last->next != NULL)
last = last->next;
last->next = new_node;
return;
void deleteNode(struct node** head, int key) {
struct node* temp = *head, *prev;
}
printf("The given previous node cannot be NULL\n");
return;
}
struct node* new_node = (struct node*)malloc(sizeof(struct node));
new_node->data = data;
new_node->next = prev_node->next;
prev_node->next = new_node;
}
if (temp != NULL && temp->data = key) {
*head = temp->next;
free(temp);
return;
}
while (temp != NULL && temp->data != key) {
prev = temp;
temp = temp->next;
}
void swapNodes (struct node** head, int x, int y) {
if (x = y) return;
struct node *prevX = NULL, *currX = *head;
while (currx && currx->data != x) {
}
if (temp == NULL) return;
prev->next = temp->next;
free(temp);
prevx = currx;
currX = currx->next;
}
struct node *prevY = NULL, *curry = *head;
while (curry && curry->data != y) {
prevY = curry;
curry = curry->next;
}
if (currX == NULL || currY = NULL) return;
if (prevx != NULL) prevX->next = curry;
else *head = curry;
}
void printList(struct node* head) {
while (head != NULL) {
}
if (prevY != NULL) prevY->next = currx;
else *head = currx;
struct node* temp = curry->next;
curry->next = currX->next;
currx->next = temp;
printf("%d", head->data);
head = head->next;
printf("\n");
int main() {
struct node* head = NULL;
insertAtEnd(&head, 1);
insertAtEnd(&head, 2);
insertAtBeginning (&head, 3);
insertAfter (head->next, 4);
printf("Linked List: ");
printList(head);
deleteNode(&head, 3);
printf("Linked List after deletion of 3: ");
printList(head);
swapNodes (&head, 1, 2);
printf("Linked List after swapping 1 and 2: ");
printList(head);
return 0;
- OX
Transcribed Image Text:#include <stdio.h> #include <stdlib.h> #include "linked_lists.h" void insertAtBeginning(struct node** head, int data) { struct node* new_node = (struct node*)malloc(sizeof(struct node)); new_node->data = data; new_node->next = *head; *head = new_node; } void insertAtEnd(struct node** head, int data) { struct node* new_node = (struct node*)malloc(sizeof(struct node)); struct node* last = *head; new_node->data = data; new_node->next = NULL; if (*head = NULL) { *head = new_node; return; } void insertAfter (struct node* prev_node, int data) { if (prev_node == NULL) { } } while (last->next != NULL) last = last->next; last->next = new_node; return; void deleteNode(struct node** head, int key) { struct node* temp = *head, *prev; } printf("The given previous node cannot be NULL\n"); return; } struct node* new_node = (struct node*)malloc(sizeof(struct node)); new_node->data = data; new_node->next = prev_node->next; prev_node->next = new_node; } if (temp != NULL && temp->data = key) { *head = temp->next; free(temp); return; } while (temp != NULL && temp->data != key) { prev = temp; temp = temp->next; } void swapNodes (struct node** head, int x, int y) { if (x = y) return; struct node *prevX = NULL, *currX = *head; while (currx && currx->data != x) { } if (temp == NULL) return; prev->next = temp->next; free(temp); prevx = currx; currX = currx->next; } struct node *prevY = NULL, *curry = *head; while (curry && curry->data != y) { prevY = curry; curry = curry->next; } if (currX == NULL || currY = NULL) return; if (prevx != NULL) prevX->next = curry; else *head = curry; } void printList(struct node* head) { while (head != NULL) { } if (prevY != NULL) prevY->next = currx; else *head = currx; struct node* temp = curry->next; curry->next = currX->next; currx->next = temp; printf("%d", head->data); head = head->next; printf("\n"); int main() { struct node* head = NULL; insertAtEnd(&head, 1); insertAtEnd(&head, 2); insertAtBeginning (&head, 3); insertAfter (head->next, 4); printf("Linked List: "); printList(head); deleteNode(&head, 3); printf("Linked List after deletion of 3: "); printList(head); swapNodes (&head, 1, 2); printf("Linked List after swapping 1 and 2: "); printList(head); return 0; - OX
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Graphical User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education