Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dwu kieunkowa lista.cpp: Określa punkt wejścia dla aplikacji konsoli.
- //
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct lista
- {
- int id;
- struct lista *pop;
- struct lista *nast;
- }list;
- struct lista *head;
- void tworzenie(int x)
- {
- list *newl = (list*)malloc(sizeof(list));
- newl->id = x;
- newl->pop = NULL;
- newl->nast = NULL;
- return newl;
- }
- void add(int x)
- {
- list *temp = (list*)malloc(sizeof(list));
- temp->id = x;
- temp->pop = NULL;
- temp->nast = NULL;
- if (head == NULL)
- {
- head = temp;
- return;
- }
- head->pop = temp;
- temp->nast = head;
- head = temp;
- }
- void wypis()
- {
- list *temp = head;
- while (temp != NULL)
- {
- printf("%d -> ", temp->id);
- temp = temp->nast;
- }
- printf("null\n");
- }
- void wypis1()
- {
- list *temp = head;
- while (temp->nast != NULL)
- {
- temp = temp->nast;
- }
- while (temp != NULL)
- {
- printf("%d ->", temp->id);
- temp = temp->pop;
- }
- printf("null \n");
- }
- int main()
- {
- head = NULL;
- int i = 0;
- int x;
- while (i < 5)
- {
- printf("daj liczbe ");
- scanf("%d", &x);
- add(x);
- i++;
- }
- printf("\n");
- printf("wypis 1: ");
- wypis();
- printf("\nwypis 2: ");
- wypis1();
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement