Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct struktura {
- int id;
- struct struktura *next;
- };
- void show( struct struktura *head ){
- struct struktura *p;
- p = head;
- while ( p != NULL ){
- printf("%d ", p->id);
- p = p->next;
- }
- }
- void add( struct struktura **head, int id ){
- struct struktura *p, *q;
- if ( *head == NULL ){
- p = (struct struktura*)malloc(sizeof( struct struktura ));
- *head = p;
- p->id = id;
- p->next = NULL;
- } else {
- p = *head;
- while ( p->next != NULL ){
- p = p->next;
- }
- q = (struct struktura*)malloc(sizeof( struct struktura ));
- p->next = q;
- q->next = NULL;
- q->id = id;
- }
- }
- void pushFront( struct struktura **head, int id ){
- struct struktura *nowy;
- nowy = (struct struktura*)malloc(sizeof( struct struktura ));
- nowy->id = id;
- nowy->next = *head;
- *head = nowy;
- }
- int main(){
- struct struktura *head;
- head = NULL;
- add(&head, 1);
- add(&head, 2);
- add(&head, 3);
- add(&head, 4);
- add(&head, 5);
- pushFront(&head, 6);
- show(head);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement