lista_pokazivac.h


/ Published in: C++
Save to your folder(s)

Zaglavlje za pokazivace


Copy this code and paste it in your HTML
  1. struct tdatum {
  2. short dan, mj, god;
  3. };
  4.  
  5. struct tEl{
  6. int sifra;
  7. char vrsta[50],naziv[50];
  8. tdatum dat;
  9. float cijena;
  10. };
  11.  
  12. struct tLista{
  13. tEl ziv;
  14. tLista *s;
  15. };
  16.  
  17. tLista *lista= new tLista;
  18. int sifra=1,br_elem=0,h=0;
  19.  
  20. void InitL(tLista *lista) {
  21. lista->s=NULL;
  22. }
  23.  
  24. void InsertL(tEl x,int p,tLista *lista) {
  25. tLista *zadnji=lista;
  26. for(int i=0;i<p;i++) zadnji=zadnji->s;
  27. tLista *novi = new tLista;
  28. zadnji->s=novi;
  29. novi->ziv=x;
  30. novi->s=NULL;
  31. }
  32.  
  33. tEl RetrieveL(int p,tLista* lista) {
  34. tLista *tekuci = lista->s;
  35. for(int i=0;i<p;i++) tekuci=tekuci->s;
  36. return tekuci->ziv;
  37. }
  38.  
  39. int EndL(tLista *lista) {
  40. tLista* tekuci=lista;
  41. int p=0;
  42. while(tekuci->s) {
  43. tekuci=tekuci->s;
  44. p++;
  45. }
  46. return p;
  47. }
  48.  
  49. void DeleteL(int p, tLista *lista) {
  50. tLista *brisi = lista->s,*prethodni=lista;
  51. for(int i=0;i<p;i++) {
  52. prethodni=brisi;
  53. brisi=brisi->s;
  54. }
  55. prethodni->s=brisi->s;
  56. delete brisi;
  57. }
  58.  
  59.  
  60. int LocateL(char x[],tLista* lista) {
  61. tLista *tekuci=lista;
  62. int p=0;
  63. while(tekuci) {
  64. if(tekuci->s==NULL) return EndL(lista);
  65. if(!strcmp((tekuci->s)->ziv.naziv,x)||(h==1&&!strcmp((tekuci->s)->ziv.vrsta,x))) return p;
  66. tekuci=tekuci->s;
  67. p++;
  68. }
  69. return EndL(lista);
  70. }
  71.  
  72. int FirstL(tLista* lista) {
  73. if(lista->s==NULL) return EndL(lista);
  74. return 0;
  75. }
  76.  
  77. int PreviousL(int p,tLista* lista) {
  78. if(p==FirstL(lista)) return -1;
  79. return p-1;
  80. }
  81.  
  82. int NextL(int p,tLista* lista) {
  83. if(p==EndL(lista)) return -1;
  84. if(p==PreviousL(EndL(lista),lista)) return EndL(lista);
  85. return p+1;
  86. }
  87.  
  88. void DeleteAllL(tLista* lista) {
  89. tLista* prethodni=lista,*tekuci=lista->s;
  90. while(tekuci) {
  91. delete prethodni;
  92. prethodni=tekuci;
  93. tekuci=tekuci->s;
  94. }
  95.  
  96. delete prethodni;
  97. lista=NULL;
  98. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.