Wednesday, March 18, 2015

#6 Levo spregnuta lista

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<malloc.h>

typedef char string10[10];
struct cvor{
        string10 ime_cvora;
        struct cvor *prethodni;
        };
typedef cvor LCVOR;

void lista_ispis(LCVOR *tekuci){
  while (tekuci!=NULL){
    tekuci=tekuci->prethodni;
    printf("%s ",tekuci->ime_cvora);    
   }  
}


main(){

 LCVOR *pocetakListe, *novi;
 char ch[20];
 pocetakListe=NULL;
 printf("\n Unesi sadrzaj liste :\n");

 do{
    scanf("%s",&ch);
    novi = (LCVOR*)malloc(sizeof(LCVOR));
    strcpy(novi->ime_cvora,ch);
    novi->prethodni = pocetakListe;
    pocetakListe=novi;      
       
   }while(strcmp(ch,"kraj")!=0);
 
   printf("Sadrzaj Liste je :\n");
   lista_ispis(pocetakListe);
 
 getch();    
}

No comments:

Post a Comment