Sunteți pe pagina 1din 1

LISTA CIRCULARA struct VideoCard LISTA CIRCULARA DUBLA

{ LS
char* name;
List* insertNode(List* list, List* node) int price; List* createNode(VideoCard* data)
{ }; {
if (list == NULL) struct List List* node = NULL;
{ { node = (List*)malloc(sizeof(List));
node->next = node; VideoCard* data; node->data = data;
list = node; List* next; node->next = NULL;
} }; node->prev = NULL;
else VideoCard* createData(char* name, int price) return node;
{ { }
node->next = list; VideoCard* videoC = NULL;
List* stop = list; videoC = (VideoCard*)malloc(sizeof(VideoCard));
while (stop->next != list) videoC->name = (char*)malloc(sizeof(char)*(strlen(name) + 1)); List* insertNode(List* list, List* node)
{stop = stop->next;} strcpy(videoC->name, name); {
stop->next = node; videoC->price = price; if (list == NULL)
} return videoC; {
list = node; } node->next = node;
return list; List* insertNode(List* list, List* node) node->prev = node;
} { list = node;
node->next = list; }
void display(List* list) list = node; else
{ return list; {
List* train = list; } node->next = list;
while (train->next!=list) void display(List* list) list->prev = node;
{ { List* stop = list;
printf("", train->data->name, train->data->price); while (list) while (stop->next != list)
train = train->next; printf(" %s %d \n", list->data->name, list->data->price); {stop = stop->next;}
} list = list->next; stop->next = node;
printf("", train->data->name, train->data->price); } node->prev = stop;
} void main() }
{ list = node;
FILE* f = NULL; return list;
void InsertNode2(List* &list)
f = fopen("Text.txt", "r"); }
{
List* list = NULL;
VideoCard* video;
char buffer[100];
List* node;
int price; void display2(List* list)
char buffer[100];
printf(" insert the NAME in the list: \n"); if (!f) {
scanf("%s", buffer); printf("There was an error opening the file!"); printf("\nList from tail to head:\n");
int price; else{ list = list->prev;
printf(" insert the PRICE in the list: \n"); fscanf(f, "%s", buffer); List* train = list;
scanf("%d", &price); while (!feof(f)) while (train->prev != list)
printf("-------------\n"); { {
fscanf(f, "%d", &price); printf("", train->data->name, train->data->price);
video = createData(buffer, price);
VideoCard* video = createData(buffer, price); train = train->prev;
node = createNode(video);
List* node = createNode(video); }
list = insertNode(list, node);
list = insertNode(list, node); printf("", train->data->name, train->data->price);
}
fscanf(f, "%s", buffer); }
}
}
display(list);}

S-ar putea să vă placă și