#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> struct Node { char name[30]; struct Node* next; }; struct Node* head = NULL; struct Node* tail = NULL; void print() { struct Node* n = head; while (n != NULL) { printf("%s \n", n->name); n = n->next; } } void push(char *n) { struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); strcpy(new_node->name, n); new_node->next = NULL; if (head == NULL) { head = new_node; tail = head; } else { tail->next = new_node; tail = new_node; } } int main() { push("Diana"); push("Andriy"); push("Taras"); print(); _getch(); return 0; }
Diana
Andriy
Taras
Andriy
Taras