idastan97

CSCI151 L26 P1

Nov 9th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. /*
  2.  * prog.c
  3.  *
  4.  *  Created on: Nov 10, 2016
  5.  *      Author: dastan.iyembergen
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. typedef struct _letter{
  11.     char c;
  12.     struct _letter *link;
  13. } letter;
  14.  
  15. void printAZ(letter *f){
  16.     if (f==NULL)
  17.         return;
  18.     printf("%c ", (*f).c);
  19.     printAZ((*f).link);
  20. }
  21.  
  22. void printZA(letter *fp){
  23.     if (fp==NULL)
  24.         return;
  25.     printZA((*fp).link);
  26.     printf("%c ", (*fp).c);
  27. }
  28.  
  29. int main(void) {
  30.     letter *first=NULL;
  31.     letter *prev=NULL;
  32.     int i;
  33.     for (i=0; i<26; i++){
  34.         letter *ch=(letter*)malloc(sizeof(letter));
  35.         (*ch).c='a'+i;
  36.         (*ch).link=NULL;
  37.         if (first==NULL){
  38.             first=ch;
  39.         } else{
  40.             (*prev).link=ch;
  41.         }
  42.         prev=ch;
  43.     }
  44.     printAZ(first);
  45.     printf("\n");
  46.     printZA(first);
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment