Advertisement
Guest User

Untitled

a guest
Sep 11th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /*SI = Simplu înlantuită
  5.  *DI = Dublu înlantuită
  6.  *DIS = Dublu înlantuită cu santinelă
  7. */
  8.  
  9. typedef struct Nod {
  10.     struct Nod *next, *ant;
  11.     int x;
  12. } Nod_t, *List_t, **AList_t;
  13.  
  14. void PrintList (List_t sant){
  15.     List_t lista = sant->next;
  16.     while(lista != sant){
  17.         printf("%i ", lista->x);
  18.         lista = lista->next;
  19.     }
  20. }
  21.  
  22. List_t PopulateList(char* fis){
  23.    
  24.     List_t lista, sant;
  25.     int nr;
  26.     FILE *f = fopen(fis, "rt");
  27.    
  28.     sant = (List_t)malloc(sizeof(List_t));
  29.     sant->next = sant->ant = NULL;
  30.     lista = sant;
  31.     //First node
  32.    
  33.     while(!feof(f)){
  34.         fscanf(f, "%i", &nr);
  35.         lista->next = (List_t)malloc(sizeof(List_t));
  36.         lista->next->x = nr;
  37.         lista->next->ant = lista;
  38.         lista = lista->next;
  39.     }
  40.    
  41.     sant->ant = lista;
  42.     lista->next = sant;
  43.    
  44.     return sant;
  45.  
  46. }
  47.  
  48. int main (){
  49.  
  50.     List_t lista1;
  51.     lista1 = PopulateList("1.txt");
  52.     PrintList(lista1);
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement