Advertisement
Archangelpl

Untitled

Jun 26th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. // dwu kieunkowa lista.cpp: Określa punkt wejścia dla aplikacji konsoli.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. typedef struct lista
  9. {
  10. int id;
  11. struct lista *pop;
  12. struct lista *nast;
  13.  
  14. }list;
  15. struct lista *head;
  16. void tworzenie(int x)
  17. {
  18. list *newl = (list*)malloc(sizeof(list));
  19. newl->id = x;
  20. newl->pop = NULL;
  21. newl->nast = NULL;
  22. return newl;
  23. }
  24. void add(int x)
  25. {
  26. list *temp = (list*)malloc(sizeof(list));
  27.  
  28. temp->id = x;
  29. temp->pop = NULL;
  30. temp->nast = NULL;
  31. if (head == NULL)
  32. {
  33. head = temp;
  34. return;
  35. }
  36. head->pop = temp;
  37. temp->nast = head;
  38. head = temp;
  39. }
  40. void wypis()
  41. {
  42. list *temp = head;
  43.  
  44. while (temp != NULL)
  45. {
  46. printf("%d -> ", temp->id);
  47. temp = temp->nast;
  48. }
  49. printf("null\n");
  50. }
  51. void wypis1()
  52. {
  53. list *temp = head;
  54. while (temp->nast != NULL)
  55. {
  56. temp = temp->nast;
  57. }
  58. while (temp != NULL)
  59. {
  60. printf("%d ->", temp->id);
  61. temp = temp->pop;
  62. }
  63. printf("null \n");
  64. }
  65. int main()
  66. {
  67. head = NULL;
  68. int i = 0;
  69. int x;
  70. while (i < 5)
  71. {
  72. printf("daj liczbe ");
  73. scanf("%d", &x);
  74. add(x);
  75. i++;
  76. }
  77.  
  78. printf("\n");
  79. printf("wypis 1: ");
  80. wypis();
  81. printf("\nwypis 2: ");
  82. wypis1();
  83. printf("\n");
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement