Posted By

KrsnikNatalija on 11/11/12


Tagged

1 podatakazadatak BibliotekapoljahStrukture


Versions (?)

Biblioteka_polja.h


 / Published in: C++
 

URL: http://e.foi.hr/wiki/strukture_podataka/index.php?title=Zadatak_1_Krsnik_Natalija&action=submit

Biblioteka_polja.h

  1. struct ziv {
  2. //----------------------------------------------------
  3. int sifra,dan,mjesec,godina;
  4. char naziv[40],vrsta[40];
  5. float cijena;
  6. };//----------------------------------------------------
  7. struct tlist {
  8. //----------------------------------------------------
  9. ziv*element[1000];
  10. int kursor;
  11. };//----------------------------------------------------
  12. int FirstL( tlist*g ) {
  13. //----------------------------------------------------
  14. return 0;
  15. }//----------------------------------------------------
  16. int EndL( tlist*g ) {
  17. //----------------------------------------------------
  18. return g->kursor;
  19. }//----------------------------------------------------
  20. int NextL( int k,tlist*g ) {
  21. //----------------------------------------------------
  22. return k+1;
  23. }//----------------------------------------------------
  24. int PreviousL( int k,tlist*g ) {
  25. //----------------------------------------------------
  26. return k-1;
  27. }//----------------------------------------------------
  28. int LocateL( int n,tlist*g ) {
  29. //----------------------------------------------------
  30. for( int i=0; i<g->kursor; i++ )
  31. if( n==g->element[i]->sifra )return i;
  32. return g->kursor;
  33. }//----------------------------------------------------
  34. int DeleteL( int k, tlist*g ) {
  35. //----------------------------------------------------
  36. k--;
  37. if( k>g->kursor ) {} else {
  38. for( int i=k; i<g->kursor; i++ )
  39. g->element[i]=g->element[i+1];
  40. g->kursor--;
  41. }
  42. }//----------------------------------------------------
  43. void InsertL( ziv*novi, int k, tlist*g) {
  44. if( k>EndL( g ) )return;
  45. else {
  46. for ( int i = EndL( g ); i > k; i-- )
  47. g->element[i] = g->element[i-1];
  48. g->element[k] = novi;
  49. g->kursor ++;
  50. }
  51. }//----------------------------------------------------
  52. void DeleteAll( tlist*g ) {
  53. g->kursor=0;
  54. }//----------------------------------------------------
  55. int NumberL( tlist*g ) {
  56. return g->kursor;
  57. }//----------------------------------------------------
  58. ziv*RetrieveL( int k,tlist*g ) {
  59. return g->element[k-1];
  60. }//----------------------------------------------------
  61. tlist*InitL( tlist*g ) {
  62. g= new tlist;
  63. g->kursor=0;
  64. return g;
  65. }//----------------------------------------------------

Report this snippet  

You need to login to post a comment.