Advertisement
Archangelpl

Untitled

Jun 26th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 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 add(int x)
  17. {
  18. list *temp = (list*)malloc(sizeof(list));
  19.  
  20. temp->id = x;
  21. temp->pop = NULL;
  22. temp->nast = NULL;
  23. if (head == NULL)
  24. {
  25. head = temp;
  26.  
  27. }
  28. else
  29. {
  30. head->pop = temp;
  31. temp->nast = head;
  32. head = temp;
  33. }
  34. }
  35. void wypis()
  36. {
  37. list *temp = head;
  38.  
  39. while (temp != NULL)
  40. {
  41. printf("%d -> ", temp->id);
  42. temp = temp->nast;
  43. }
  44. printf("null\n");
  45. }
  46. void wypis1()
  47. {
  48. list *temp = head;
  49. while (temp->nast != NULL)
  50. {
  51. temp = temp->nast;
  52. }
  53. while (temp != NULL)
  54. {
  55. printf("%d ->", temp->id);
  56. temp = temp->pop;
  57. }
  58. printf("null \n");
  59. }
  60. int main()
  61. {
  62. head = NULL;
  63. int i = 0;
  64. int x;
  65. while (i < 5)
  66. {
  67. printf("daj liczbe ");
  68. scanf("%d", &x);
  69. add(x);
  70. i++;
  71. }
  72.  
  73. printf("\n");
  74. printf("wypis 1: ");
  75. wypis();
  76. printf("\nwypis 2: ");
  77. wypis1();
  78. printf("\n");
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement