Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. struct state{
  5. struct state *a;
  6. struct state *b;
  7. int numberOfState;
  8. int finall;
  9. };
  10.  
  11. int add(int numberOfState, struct state *a, struct state *b int finall){
  12.     if(h==NULL){
  13.         h=(struct state*)malloc(sizeof(struct state));
  14.         h->a=a;
  15.         h->b=b;
  16.         h->finall=0;
  17.         h->numberOfState=numberOfState;
  18.         return 0;
  19.     }
  20.     else if(value >= h->value){
  21.  
  22.         if(h->right!=NULL)
  23.         add(value,h->right);
  24.  
  25.         else{
  26.         h->right=(struct state*)malloc(sizeof(struct state));
  27.         h->a=a;
  28.         h->b=b;
  29.         h->finall=0;
  30.         h->numberOfState=numberOfState;
  31.         return 0;
  32.         }
  33.     }
  34.  
  35.  
  36.     else if(value < h->value){
  37.  
  38.         if(h->left!=NULL)
  39.         add(value,h->right);
  40.  
  41.         else{
  42.         h->left=(struct state*)malloc(sizeof(struct state));
  43.         h->a=a;
  44.         h->b=b;
  45.         h->finall=0;
  46.         h->numberOfState=numberOfState;
  47.         return 0;
  48.         }
  49.     }
  50.  
  51. }
  52.  
  53. int move(struct state *current, char selection){
  54. return current->selection;
  55. }
  56.  
  57. void main(){
  58.  
  59. struct state *states[4];
  60. struct state *current;
  61. char control;
  62. String string;
  63. String stateMoves;
  64.  
  65. struct state *states[0]=malloc;
  66. struct state *states[1]=malloc;
  67. struct state *states[2]=malloc;
  68. struct state *states[3]=malloc;
  69.  
  70. add(0,states[1],states[2],0);
  71. add(1,states[2],states[3],0);
  72. add(2,states[2],states[2],1);
  73. add(3,states[3],states[3],0);
  74.  
  75. current=state[0];
  76.  
  77.     do{
  78.     control=getch();
  79.  
  80.         if(control=='a' || control=='b'){
  81.         addToAnArray(stateMoves, current->numberOfState);
  82.         addToAnArray(strings, control);
  83.         current=move(current, control);
  84.         }
  85.  
  86.         else
  87.         printf("enter a valid move\n");
  88.  
  89.     }while(control!=32);
  90.  
  91. for(i=0;i<strlen(moves))
  92. printf("%c",moves[i]);
  93.  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement