Advertisement
peterzig

[AISD] Kolejka Priorytetowa

Sep 21st, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. // [AISD] Kolejka Priorytetowa.cpp : Defines the entry point for the console application.
  2. //
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. struct queue
  7. {
  8.     int pamiec;
  9.     struct queue *nastepny;
  10. };
  11. struct queue *ogon = NULL;
  12. struct queue *glowa = NULL;
  13. void push(int liczba)
  14. {
  15.     struct queue *mem = (struct queue*)malloc(sizeof(struct queue));
  16.     mem->pamiec = liczba;
  17.     mem->nastepny = NULL;
  18.     if (ogon == NULL && glowa == NULL)
  19.     {
  20.         glowa = ogon = mem;
  21.         return;
  22.     }
  23.     ogon->nastepny = mem;
  24.     ogon = mem;
  25. }
  26. void pop()
  27. {
  28.     struct queue *mem = glowa;
  29.     if (glowa == NULL) return;
  30.     if (glowa == ogon)
  31.     {
  32.         glowa = ogon = NULL;
  33.     }
  34.     else
  35.     {
  36.         glowa = glowa->nastepny;
  37.  
  38.     }
  39.     free(mem);
  40. }
  41. int Przod()
  42. {
  43.     if (glowa == NULL)
  44.     {
  45.         printf("Kolejka jest pusta");
  46.         return 0;
  47.     }
  48.     return (glowa->pamiec);
  49. }
  50. void Pokaz()
  51. {
  52.     struct queue *wsk = glowa;
  53.     while (wsk != NULL)
  54.     {
  55.         printf("%d", wsk->pamiec);
  56.  
  57.         wsk = wsk->nastepny;
  58.     }
  59.     printf("\n");
  60.  
  61. }
  62.  
  63. int main()
  64. {
  65.     printf("Kolejka:");
  66.     push(2);
  67.     Pokaz();
  68.     printf("Kolejka:");
  69.     push(4);
  70.     Pokaz();
  71.     printf("Kolejka:");
  72.     push(3);
  73.     Pokaz();
  74.     printf("Kolejka:");
  75.     push(8);
  76.     Pokaz();
  77.     printf("Kolejka:");
  78.     push(1);
  79.     Pokaz();
  80.     printf("Kolejka:");
  81.     Pokaz();
  82.     printf("Glowa:");
  83.     printf("%d", Przod());
  84.     _getch();
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement