Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Giving this struct, Write a C program typedef struct songInfo { char pArtist[29]; char pTitle[29]; int ranking; } songs; Put the input into a sorted

Giving this struct, Write a C program

typedef struct songInfo { char pArtist[29]; char pTitle[29]; int ranking; } songs;

Put the input into a sorted doubly-linked list ,where the sorting is done by ascending by rating (e.g. 1 comes before 4).

  • If two songs have the same rating, you can arbitrarily choose which song to put first.
    • The sorting must be done such that each element is inserted into the proper location in the list in turn. Do not create an unsorted list and then sort the list afterwards (doing this would result in a failing mark for the assignment).
    • At the same time, put the song into another separate sorted linked list, where the sorting is done ascending by artist (e.g. Coldplay comes before U2). If two songs have the same artist, you can arbitrarily choose which song to put first.
    • The user will never enter a song with an artist and title that is already in the list (e.g. if "Beautiful Day" by "U2" is in the list already, the user will not ask you to enter it again).
    • This means that you will have two separate head pointer variables and two separate tail pointer variables.
  • Stop getting user input once an invalid artist of "." is entered by the user.
    • You should ignore the song that had the invalid artist (i.e. don't put it into the linked list).
  • After the input is complete, traverse the ratings-sorted linked list, displaying one song per line with artist (left-justified with a width of 35 characters), title (left-justified with a width of 35 characters), and rating (left-justified).
  • Next, traverse the artist-sorted linked list, displaying with the same output format as the previous traversal.
  • Next, obtain one song as additional user input in the same format as before. Search for that song in the artist-sorted linked list.
    • If there is a match of artist, title, and rating, prompt for a new rating.
      • If the rating is changed, update the artist-sorted linked list with the new rating. Then delete the song from the rating-sorted linked list and re-insert it.
      • If the rating is unchanged, do nothing.
      • The rating will always be a valid rating between 1 and 5 inclusive (e.g. I won't test your code by entering a rating of -4).
    • If there is not an exact match, simply ignore the change and continue with the next step (i.e. just redisplay both linked lists).
  • Redisplay both linked lists as before.
  • Once completely done, you must free all allocated memory.

Additional Functions

  • Create the findSong() function. It returns NULL if a song is not found or it returns a pointer to the node containing a song, if both the title and artist are matched (with a case-sensitive match, so you can use strcmp for this). It takes three parameters:
      • songNode *head: head of list
      • char *artist: pointer to null-terminated string containing artist
      • char *title: pointer to null-terminated string containing title
    • If only the artist or the title are found but both are not found in the same node, the song is not found.
  • Create the deleteNode() function. It deletes a node, using three parameters:
      • songNode *node: node to delete
      • songNode **head: pointer to head of list
      • songNode **tail: pointer to tail of list
    • The key to this function is relinking pointers around the node before deleting.
    • If node is NULL, it returns immediately.
    • It returns nothing.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

L A -r- P[N]

Answered: 1 week ago