Sunday, October 21, 2012

SINGLY LINKED LIST and Different OPERATION on it





#include
#include
struct node {
       int data;
       struct node *next;
       }*start;
      
main()
{
      int choice,n,m,position,i;
      start=NULL;
      while(1)
      {
              printf("1.Create List\n");
              printf("2.Add at begining\n");
              printf("3.Add after\n");
              printf("4.Delete\n");
              printf("5.Display\n");
              printf("6.Count\n");
              printf("7.Reverse\n");
              printf("8.Search\n");
              printf("9.Quit\n");
              printf("Enter Your Choice:");
              scanf("%d",&choice);
              switch(choice)
              {
                            case 1:
                                 printf("How many nodes you want:");
                                 scanf("%d",&n);
                                 for(i=0;i                                 {
                                                 printf("Enter the Element: ");
                                                 scanf("%d",&m);
                                                 create_list(m);
                                 }
                                 break;
                            case 2:
                                 printf("Enter the element :");
                                 scanf("%d",&m);
                                 addatbeg(m);
                                 break;
                            case 3:
                                 printf("Enter the element: ");
                                 scanf("%d",&m);
                                 printf("Enter the position after which element is inserted: ");
                                 scanf("%d",&position);
                                 addafter(m,position);
                                 break;
                            case 4:
                                 if(start==NULL)
                                 {
                                            printf("List is empty\n");
                                            continue;
                                 }
                                 printf("Enter the element for deletion:");
                                 scanf("%d",&m);
                                 del(m);
                                 break;
                            case 5:
                                 display();
                                 break;
                            case 6:
                                 count();
                                 break;
                            case 7:
                                 rev();
                                 break;
                            case 8:
                                 printf("Enter the element need to be searched:");
                                 scanf("%d",&m);
                                 search(m);
                                 break;
                            case 9:
                                 exit(1);
                            default:
                                 printf("Wrong Choice\n");
                      }
              }
   
      }
create_list(int num)
{
   struct node *temp,*q;
   temp = malloc(sizeof(struct node));
   temp->data=num;
   temp->next=NULL;
   if(start == NULL)
    {
        start=temp;
    }
    else
    {
        q=start;
        while(q->next!=NULL)
            q=q->next;
        q->next=temp;                           
    }
}
addatbeg(int num)
{
        struct node *temp;
        temp=malloc(sizeof(struct node));
        temp->data=num;
        temp->next=start;
        start=temp;
}
addafter(int num, int pos)
{
        struct node *temp ,*q;
        int count=1;
        temp=malloc(sizeof(struct node));
        temp->data=num;
        q=start;
        while(q!=NULL)
        {
         if(pos==count)
         {
                       temp->next=q->next;
                       q->next=temp;
         }
         count++;
         q=q->next;
        }
}       
del(int num)
{
        struct node *temp,*q;
        if(start->data==num)
        {
                       temp =start;
                       start=start->next;
                       free(temp);
                       return;
        }
        q=start;
        while(q->next->next!=NULL)
        {
         if(q->next->data==num)
             {
                                   temp=q->next;
                                   q->next=temp->next;
                                   free(temp);
                                   return;
              }       
              q=q->next;
        }
        if(q->next->data==num)
        {
                              temp=q->next;
                              free(temp);
                              q->next=NULL;
                              return;
        }
        printf("Element not found in the List\n");
}      

display()
{
         struct node *q;
         if(start==NULL)
         {
                        printf("Empty List\n");
                        return;
         }
         q=start;
         printf("Elements are:");
         while(q!=NULL)
         {
                             if(q->next!=NULL)
                             printf("%d,",q->data);
                             else
                             printf("%d.\n",q->data);
                             q=q->next;
           
         }
         printf("\n");
}       
count()
{
       struct node *q;
       int cnt;
       if(start==NULL)
       {
                      printf("Zero Element\n");
                      return;
       }
       q=start;
       while(q!=NULL)
       {
            cnt++;
            q=q->next;
                      
       }
       printf("The number of Elements in the list:%d\n",cnt);
}
rev()
{  
     struct node *p1,*p2,*p3;
     if(start->next==NULL)
     {
                          printf("Only one Element is present\n");
                          return;
     }
     if(start->next->next ==NULL)
     {
                          p1 = start;
                          p2= p1->next;
                          p2->next= p1;
                          p1->next=NULL;
                          start = p2;
                          return;
     }
     p1=start;
     p2=p1->next;
     p3=p2->next;
     p1->next=NULL;
     p2->next=p1;
     while(p3!=NULL)
     {
                    p1=p2;
                    p2=p3;
                    p3=p3->next;
                    p2->next=p1;
     }
     start=p2;                                        
}
search(int num)
{
    struct node *q;
    q=start;
    int pos =1;
    while(q!=NULL)
    {
           if(q->data==num)
           {
                    printf("Element %d found at pos=%d\n",num,pos);
                    return;
           }
           pos++;
           q=q->next;
    }
    if(q==NULL)
    printf("Element %d nod found in the list\n",num);
}

Friday, September 14, 2012

SYSTEM CLOCKS



CLOCK_REALTIME : it gives the access to the real time clock (RTC) , i.e. the one that stores the current date and time.

     A key difference between an RTC and the system clock is that RTCs run even
     when the system is in a low power state (cpu Idle), and the system  clock can't. 
     Until it is initialized, the system clock can only report time since system boot, not 
     since the POSIX Epoch.  So at boot time, and after resuming from a system low 
     power state, the system clock will often be set to the current wall clock time using 
     an RTC.



CLOCK_MONOTONIC : it gives the access to a clock ( cpu ticks ) that never goes back in time .It takes the CPU Hz.

 It goes off when there will be no Hz ( cpu Idle state) . So when again CPU gets up ,
 it adds the sleeping time using another components input timerkeeping timer,
 basically a rough time. So it should be used in the usecase wherever we need delta 
 of time.Irrespective of cpu state during playback , whenever we do clock_gettime ,this
 clock will be there.
Basically these are clock_ids which provides clock source when we use clock_gettime()

otherwise to get the phone time , we can use gettimeofday() , this will change whenever there
will be change in wall time.

Wednesday, September 12, 2012

Android Streaming



    Streaming on Android Phone
  • HTTP , PDL , Youtube 
  • HLS - Live streaming
  • DRM - Widevine
  • RTSP




 

Tuesday, September 11, 2012

Matrix


Q -1 Write a program to transpose the given 4 x 4 matrix  and count the number of swapping operation will be done.

program -

#include stdio.h
#include conio.h
int a[4][4];
inline int Transpose()
{
       int temp,l,m,c=0;
       for( l=0; l < 4 ; l ++) {
           for( m=0; m < 4 ; m++) {
               if(l  <  m) {
                 temp = a[l][m];
                 a[l][m] = a[m][l];
                 a[m][l] = temp;
                 c++;
                 }
                      
              }
              
       }
       printf("number of swaping : %d\n\n",c);
}

int main()
{
    int i,j;
    printf("Enter the matrix :");
    for (i =0;i < 4;i++)
    {
        for(j=0; j < 4; j++)
         {
                scanf("%d",&a[i][j]);
         }
    }
    printf ("Matrix 4x4:");
    for (i =0 ; i < 4; i++)
    {  
        printf("\n");
        for(j=0; j < 4; j++)
         {
                printf("%d",a[i][j]);
                printf("\t");
         }
         printf("\n");
    }
   Transpose();
   printf ("T_Matrix 4x4:");
    for (i =0 ; i < 4; i++)
    {  
        printf("\n");
        for(j=0; j < 4; j++)
         {
                printf("%d",a[i][j]);
                printf("\t");
         }
         printf("\n");
    }
    
getch();
return 0;
}


Q.2  c++ program to multiply two 4x4 matrix

for multiplication number of columns in A must be equal to number of rows in B  here m=n=4

Program :