diff --git a/Assignment 1/17CS30038_1.c b/Assignment 1/17CS30038_1.c index fe22ec4..3486d96 100644 --- a/Assignment 1/17CS30038_1.c +++ b/Assignment 1/17CS30038_1.c @@ -1,71 +1,99 @@ #include #include - #include +#include + struct node { + int data; struct node *xor; -}; + +};//End of structure -struct node *xor(struct node *a,struct node *b) + +struct node *xor( struct node *a , struct node *b ) { - return (struct node*) ((uintptr_t) a ^ (uintptr_t) b); -} -void trafte(struct node *head) + + return ( struct node* ) ( ( uintptr_t ) a ^ ( uintptr_t ) b ); + +}//End of function + + +void trafte( struct node *head ) { + int i; - struct node* temp=NULL,*prev=NULL,*temp2; - temp=head; - printf("front to end traversal\n"); - printf("%d\t",temp->data); - temp=temp->xor; - prev=head; - while(xor(temp->xor,prev)) + struct node* temp = NULL , *prev = NULL , *temp2; + temp = head; + printf( "front to end traversal\n" ); + printf( "%d\t" , temp->data ); + temp = ( temp->xor ); + prev = head; + + while( xor( temp->xor , prev ) ) { - printf("%d\t",temp->data); - temp2=prev; - prev=temp; - temp=xor(temp->xor,temp2); - } + + printf( "%d\t" , ( temp->data ) ); + temp2 = prev; + prev = temp; + temp = xor( ( temp->xor ) , temp2 ); + + }//End of while + + printf( "%d\n" , ( temp->data ) ); + +}//End of function + - printf("%d\n",temp->data); -} int main() { + int n; - scanf("%d",&n); - struct node * front=NULL,*end,*move,*temp,*prev,*temp2; ; - int i=0; - for(i=0;idata=rand()%100; - move->xor=NULL; - if(front==NULL) + + move = ( struct node* )malloc( sizeof( struct node* ) );//Allocate free space in the memory + ( move->data ) = ( rand() % 100 ); + ( move->xor ) = NULL; + + if( front == NULL ) { - front=move; + front = move; } else { - prev->xor=move; + ( prev->xor ) = move; - } - prev=move; - } - end=move; - move=front; - prev=NULL; - for(int i=0;ixor; - temp2=move; - move->xor=xor(prev,temp); - move=temp; - prev=temp2; + + temp = ( move->xor ); + temp2 = move; + ( move->xor ) = ( xor( prev , temp ) ); + move = temp; + prev = temp2; + i = ( i + 1 ) - } - move->xor=prev; - trafte(front); + }//End of while + + ( move->xor ) = prev; + trafte( front ); return 0; -} +}//End of main