Advertisement
kamillo111

kolos infwiki1

Apr 19th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct kolejka{
  5.  
  6.     int data;
  7.     kolejka * next;
  8.  
  9. };
  10.  
  11. void dodaj(kolejka *&head, kolejka *&tail, int n)
  12. {
  13.     kolejka *temp = new kolejka;
  14.     temp->data = n;
  15.  
  16.     if (head == NULL)
  17.     {
  18.         head = temp;
  19.         temp->next = NULL;
  20.         tail = head;
  21.     }
  22.     else
  23.     {
  24.         temp->next = tail;
  25.             tail = temp;
  26.        
  27.     }
  28.  
  29.  
  30. }
  31.  
  32. void podz(int n,int *tab,int k, kolejka *&head, kolejka *&tail)
  33. {
  34.     for (int i = 0; i < n; i++)
  35.     {
  36.         if (tab[i] % k == 0) dodaj(head, tail, tab[i]);
  37.  
  38.     }
  39.  
  40.  
  41. }
  42. void wys(kolejka *head, kolejka *tail)
  43. {
  44.  
  45.     while (tail != NULL)
  46.     {
  47.         cout << tail->data;
  48.         tail = tail->next;
  49.     }
  50.  
  51. }
  52.  
  53. int main()
  54. {
  55.     kolejka *head = NULL;
  56.     kolejka *tail = NULL;
  57.     int tab[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
  58.     podz(10, tab, 2, head, tail);
  59.     wys(head, tail);
  60.     system("pause");
  61.  
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement