array
JAVA array declaration and initialization
An array is group of variables that is given only one name. Each variable that makes up the array is given a number instead of a name which makes it easier to work with using loops among other things.
int[] a = new int[5];
int[] b = {12, 23, 34, 45, 56};
int[][] c = new int[3][3];
c[0][0] = 1;
int[] d = new int[5];
d[0] = 12;
d[1] = 23;
d[2] = 34;
d[3] = 45;
d[4] = 56;
Stack Implementation using array
/* Program of stack using array*/
#include
#define MAX 5
int top = -1;
int stack_arr[MAX];
main()
{
int choice;
while(1)
{
printf("1.Push\n");
printf("2.Pop\n");
printf("3.Display\n");
printf("4.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1 :
push();
break;
case 2:
pop();
break;
case 3:
Bubble Sort function for sorting an array
Pseudocode and Flowchart:-
BubbleSort( int a[], int n)
Begin
for i = 1 to n-1
sorted = true
for j = 0 to n-1-i
if a[j] > a[j+1]
temp = a[j]
a[j] = a[j+1]
a[j+1] = temp
sorted = false
end for
if sorted
break from i loop
end for
End
PHP array
An array is a mean to store collection of values in a single variable. e.g instead of creating a separate variable to store each employee's name, you can use an array to store the names of all your employees in a single variable. This is how you would do it.
$employee_names[0] = "value1"; $employee_names[1] = 10; //No matter of data type Wow..! $employee_names[2] = "Susan";

Sign In





