Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <limits.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct Node {
- char *data;
- struct Node* next;
- } Node;
- Node *add_first(Node *a, char* data)
- {
- Node *c = (Node*)malloc(1 * sizeof(Node));
- *c = { data, a };
- return c;
- }
- Node *reverse(Node* a)
- {
- Node *b = a, *c = (Node*)malloc(1 * sizeof(Node));
- *c = { a->data, NULL };
- while (b->next != NULL)
- {
- b = b->next;
- c = add_first(c, b->data);
- }
- return c;
- }
- Node *add_kvadrat(Node *a, char* data)
- {
- Node *c = (Node*)malloc(1 * sizeof(Node));
- *c = { data, a };
- if (c->next)
- c->next = reverse(c->next);
- c = reverse(c);
- return c;
- }
- void print_Node(Node *a)
- {
- if (strlen(a->data))
- printf("%s ", a->data);
- if (a->next)
- print_Node(a->next);
- else
- printf("\n");
- }
- Node *init(char* b) {
- Node *a = (Node*)malloc(sizeof(Node));
- a->data = b;
- a->next = NULL;
- return(a);
- }
- Node* getLast(Node *head) {
- if (head == NULL) {
- return NULL;
- }
- while (head->next) {
- head = head->next;
- }
- return head;
- }
- void add(Node *head, char* value) {
- Node *last = getLast(head);
- Node *tmp = (Node*)malloc(sizeof(Node));
- tmp->data = value;
- tmp->next = NULL;
- last->next = tmp;
- }
- void seminar_list() {
- FILE* f1 = freopen("in.txt", "r", stdin);
- FILE* f2 = freopen("out.txt", "w", stdout);
- Node *head;
- head = init("A");
- add(head, "B");
- add(head, "C");
- add(head, "D");
- print_Node(head);
- head = reverse(head);
- print_Node(head);
- fclose(f1);
- fclose(f2);
- }
- int main(){
- seminar_list();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement