Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- typedef struct str
- {
- int val;
- struct str* next;
- } str;
- str* copy(str* el)
- {
- str* cpy = malloc(sizeof(str));
- *cpy = *el;
- return cpy;
- }
- str* new_element(int v)
- {
- str* cpy = malloc(sizeof(str));
- cpy->val = v;
- return cpy;
- }
- str* add(str* head, str* el)
- {
- if(head != NULL)
- {
- str *a, *b, *c;
- a = b = c = head;
- do{
- a = b;
- b = c;
- c = c->next;
- }while(c!=head);
- a->next = el;
- el->next = b;
- return head;
- }
- else
- {
- el->next = el;
- return el;
- }
- }
- void main()
- {
- str head = {2, &head};
- str head2 = {5, NULL};
- str *list = &head;
- str *curr = list;
- char a; int i = 0;
- while(1)
- {
- a = getch();
- if(a == 'q')
- {
- printf("[%d] ", curr->val);
- curr = curr->next;
- }else
- {
- printf("\n");
- list = add(list, new_element(i));
- curr = list;
- }
- // printf("PRESSED '%c'", a);
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement