Posts

Showing posts from July, 2017

Rotate a matrix 270 degree AntiClockWise

#include<stdio.h> void printMt(int mat[][4]) {     int i, j;     for (i = 0; i < 4; i++) {         for (j = 0; j < 4; j++) {             printf("%d ", mat[i][j]);         }         printf("\n");     } } void AntiClock90(int mat[][4]) {     int i, j, t;     for (i = 0; i < 4 / 2; i++) {         for (j = i; j < 4; j++) {             t = mat[4 - i - 1][j];             mat[4 - i - 1][j] = mat[i][j];             mat[i][j] = t;         }     }     printf("90 anticlock\n");     printMt(mat); } void Anti270(int mat1[][4]) {     int i,j,t;     for(i=0; i<4/2; i++)     {         for( j=i; j<4; j++)         {             t=mat1[j][4-i-1];             mat1[j][4-i-1]=mat1[j][i];             mat1[j][i]=t;         }     }     printf("270 anticlock \n");     printMt(mat1); } int main() {     int mat[4][4]= {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};  

Binary Tree Creation Code Using C

#include<stdio.h> #include<stdlib.h> struct node { int key; struct node *left; struct node *right; }; struct node *createNode() { struct node *temp; temp=(struct node *)malloc(sizeof(struct node)); temp->left=NULL; temp->right=NULL; return temp; } struct node *queue[100]; int front=-1,rear=-1; int isEmptyt() {     if(front==-1||front==rear+1)     {  return 0;     }     else     {     return 1; } } void Enqueue(struct node *temp) { if(front==-1) { front=0; } rear=rear+1; queue[rear]=temp; } struct node *Dequeue() { int t; if(front==-1||front==rear+1) {  return 0; } t=front; front++; return queue[t]; } void Delete() { front=-1; rear=-1; } struct node* BinaryTree(struct node *root,int key) {      struct node *temp=createNode();      temp->key=key;      if(root==NULL)      {       root=temp;       return root; }      else      {       Enqueue(root);       while(isE

EASIEST WAY FOR MERGE TWO LINKLIST

/* Link list Node struct Node {     int data;     Node* next; }; */ Node* SortedMerge(Node* head1,   Node* head2) {     struct  Node *head,*last;     if(head1==NULL)     {         return head2;     }     if(head2==NULL)     {         return head1;     }     if(head1&&head2)     {         if(head1->data<head2->data)         {             last=head1;             head1=last->next;         }         else         {             last=head2;             head2=last->next;         }     }     head=last;     while(head1&&head2)     {         if(head1->data<head2->data)         {             last->next=head1;             last=head1;             head1=last->next;         }         else         {             last->next=head2;             last=head2;             head2=last->next;         }     }     if(head1)     {         last->next=head1;     }     if(head2)     {         last->next=head2