Advertisement
chelsea8410

pocetakjosip

Mar 30th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. struct info
  6. {
  7.     int dan,mjesec,godina;
  8.     info *sljedeci;
  9. };
  10.  
  11. info *pocetak,*kraj;
  12.  
  13. info *noviInfo();
  14. void dodajNaPocetak(info *novi);
  15. void dodajNaKraj(info *novi);
  16. void ispis();
  17. void meni();
  18. void ispisN(int broj);
  19.  
  20. int main()
  21. {
  22.     pocetak=NULL;
  23.     kraj=NULL;
  24.     int n=0,broj;
  25.     info *novi;
  26.     while(n!=9)
  27.     {
  28.        meni();
  29.        cin>>n;
  30.        system("cls");
  31.        switch(n)
  32.        {
  33.         case 1:
  34.             novi=noviInfo();
  35.             dodajNaPocetak(novi);
  36.             break;
  37.         case 2:
  38.             novi=noviInfo();
  39.             dodajNaKraj(novi);
  40.             break;
  41.         case 3:
  42.             ispis();
  43.             break;
  44.         case 4:
  45.             cout<<"Unesite broj mjeseca:->";
  46.             cin>>broj;
  47.             ispisN(broj);
  48.             break;
  49.         case 9:
  50.             cout<<"Program se zavrsava."<<endl;
  51.             break;
  52.         default:
  53.             cout<<"Ponovite odabir."<<endl;
  54.             break;
  55.        }
  56.     }
  57.     return EXIT_SUCCESS;
  58. }
  59.  
  60. info *noviInfo()
  61. {
  62.     info *temp=new info;
  63.     cout<<"Dan:->"; cin>>temp->dan;
  64.     cout<<"Mjesec:->"; cin>>temp->mjesec;
  65.     cout<<"Godina:->"; cin>>temp->godina;
  66.     temp->sljedeci=NULL;
  67.     return temp;
  68. }
  69.  
  70.  
  71. void dodajNaPocetak(info *novi)
  72. {
  73.     if(pocetak==NULL)
  74.     {
  75.         pocetak=novi;
  76.         kraj=novi;
  77.     }
  78.     else
  79.     {
  80.         novi->sljedeci=pocetak;
  81.         pocetak=novi;
  82.     }
  83. }
  84.  
  85. void dodajNaKraj(info *novi)
  86. {
  87.     if(pocetak==NULL)
  88.     {
  89.         pocetak=novi;
  90.         kraj=novi;
  91.     }
  92.     else
  93.     {
  94.         kraj->sljedeci=novi;
  95.         kraj=novi;
  96.     }
  97. }
  98.  
  99. void ispis()
  100. {
  101.     info *temp=pocetak;
  102.     while(temp!=NULL)
  103.     {
  104.     cout<<temp->dan;
  105.     cout<<"."; cout<<temp->mjesec;
  106.     cout<<"."; cout<<temp->godina<<endl;
  107.     temp=temp->sljedeci;
  108.     }
  109. }
  110.  
  111. void ispisN(int broj)
  112. {
  113.     info *temp=pocetak;
  114.     while(temp!=NULL)
  115.     {
  116.     if(temp->mjesec==broj){
  117.     cout<<temp->dan;
  118.     cout<<"."; cout<<temp->mjesec;
  119.     cout<<"."; cout<<temp->godina<<endl;
  120.     }
  121.     temp=temp->sljedeci;
  122.     }
  123.  
  124. }
  125.  
  126.  
  127. void meni(){
  128.  
  129.     cout<<"1*-Dodavanje na pocetak"<<endl;
  130.     cout<<"2*-DOdavanje na kraj"<<endl;
  131.     cout<<"3*-Ispis iz liste"<<endl;
  132.     cout<<"4*-Ispis datuma sa odredjenim mjesecom."<<endl;
  133.     cout<<"9*-EXIT"<<endl;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement