Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct xy {
- int x;
- struct xy* link;
- };
- void add (struct xy* head) {
- struct xy* tmp;
- tmp = (struct xy *) malloc (sizeof (struct xy));
- scanf ("%d", &tmp->x);
- tmp->link = NULL;
- if (head == NULL) {
- head->x = tmp->x;
- head->link = tmp->link;
- }
- else {
- struct xy* q;
- q = head;
- while (q->link != NULL) {
- q = q->link;
- }
- q->link = tmp;
- }
- }
- void print (struct xy* head) {
- struct xy* current = head;
- if (current == NULL) printf ("Brak danych w liscie.\n");
- while (current != NULL) {
- printf("x: %d\n", current->x);
- current = current->link;
- }
- }
- int main(void) {
- struct xy* head = (struct xy*) malloc (sizeof (struct xy));
- add(head);
- printf ("Linked list:\n");
- //printf ("%d", head->x);
- print(head);
- printf ("\nWypisane.");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement