Searching for "array."

Q:

Write an algorithm to separate all ones & zeroes in an array.

Answer

1. Have two indexes pointing to two ends of array, say i and j.


2. Approach towards each other with a check condition that they dont cross each other.


3. Each iteration of while loop, swap the numbers pointed by two indexes when num[i] index number is not equal to 1.


 


void sort()


{


     int a[]={1,0,0,0,1,1,0,1,0,1,0,0,1,0};


     int i=0;


     int j=13;


     int temp;


      while(j>i)


     {


          if(a[i]==1)


                 i++;


          if(a[j]==0)


                 j--;


          if(a[i]==0)


         {


                 temp=a[i];


                a[i]=a[j];


                a[j]=temp;


         }


     } 


     for(i=0;i<14;i++)


             Console.Write(a[i]+", ");


}


Output: 1,1,1,1,1,1,0,0,0,0,0,0,0

Report Error

View answer Workspace Report Error Discuss

Q:

Explain $_FILES Superglobal Array.

Answer

Array                                              Descriptions
--------------------------------           -----------------------------------
$_FILES['userfile']['name']              The original name of the file on the client machine.




$_FILES['userfile']['type']                The MIME type of the file if the browser provided 


                                                   this information. An example would be "image/gif".




$_FILES['userfile']['size']                The size, in bytes, of the uploaded file.




$_FILES['userfile']['tmp_name']      The temporary filename of the file in which the


                                                  uploaded file was stored on the server.




$_FILES['userfile']['error']              The error code  associated with this file upload.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP