how to create this type linked list
// this开发者_开发百科 is program designed to create Cd data base
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//=============================================
//LINKED LIST USED FOR CREATING THE DATABASE CD
//=============================================
struct CD_type_node
{
int CDnum;
char title[20];
int CDcount;
struct CD_type_node* next;
};
struct Artist_type_node // to create a linked list of CD's
{
struct CD_type_node CD_data;
char Artist_name[20];
struct Artist_type_node* next;
};
this is partial of the project:
1) Create a CD_type_node structure having the following fields:- CD number
- CD title
- CD count
- A pointer to CD_type_node to point to next CD.
2) Create a Artist_type_node structure having the following fields:
- Artist’s name
- A pointer to a CD_type_node, to enable you to create a linked list for CDs.
3) In your main, create an array of type Artist_type_nodes that can store up to 100 elements.
Thus, your database will be an array of 100 Artists, where each Artist has a list of CDs. Basically, each Artist’s name and a pointer to the list of CD’s will be stored in the Artist_Array.
when i compile this is what it tells me: struct CD_type_node has no element Artist_name
how do i make the correct linked list and how do i create the array
when i compile this is what it tells me: struct CD_type_node has no element Artist_name
Well, from what you've shown CD_type_node
indeed doesn't have a field called Artist_name
. Perhaps you are confusing a CD_type_node
with an Artist_type_node
object ?
Either add a string Artist_name to CD_type_node, or add a pointer to the parent Artist_type_node so you save memory. Now to achieve this first make a declaration of Artist_type_node, then implement CD_type_node and then write the implementation of Artist_type_node. To use this structure lets say you're viewing some CD_type_node and want the Artist name , you then create a new Artist_type_node and assign the pointer to it. Read the value and delete the new Artist_type_node OR have some global Artist_type_node and keep switching its pointer - but that's bad practice.
// this is program designed to create Cd data base
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//=============================================
//LINKED LIST USED FOR CREATING THE DATABASE CD
//=============================================
struct CD_type_node
{
int CDnum;
char title[20];
int CDcount;
struct CD_type_node* next;
};
struct Artist_type_node // to create a linked list of CD's
{
struct CD_type_node* CD_node;
char Artist_name[20];
};
int main()
{
struct Artist_type_node artists[100];
}
Change your Artist_type_node as I have shown.
Edit: Be sure to read carefully, because it explains to do this in your homework.
精彩评论