0% found this document useful (0 votes)
9 views5 pages

Array Complete Program

The document provides a Java program that implements basic array operations such as creation, traversal, insertion, searching, and deletion. It includes methods for each operation and a main loop for user interaction. Additionally, it contains a cheat sheet summarizing the algorithms for array traversal, insertion, deletion, and linear search.

Uploaded by

vvarthini007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Array Complete Program

The document provides a Java program that implements basic array operations such as creation, traversal, insertion, searching, and deletion. It includes methods for each operation and a main loop for user interaction. Additionally, it contains a cheat sheet summarizing the algorithms for array traversal, insertion, deletion, and linear search.

Uploaded by

vvarthini007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

Scanner;

/*

* To change this license header, choose License Headers in Project


Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author vvart

*/

public class NewMain {

/**

* @param args the command line arguments

*/

Scanner o=new Scanner ([Link]);

int ar[]=new int[50],n,j;

void cre(){

[Link]("enter no of elements");

n = [Link]();

[Link]("enter elements");

for(j=0;j<n;j++){

ar[j]=[Link]();
}}

void trav(){

for(int j=0;j<n;j++){

[Link](ar[j]);

void ins(){

int p,x;

if(n == 50){

[Link]("Array full");

return;

[Link]("enter position");

p=[Link]();

[Link]("enter data to insert");

x=[Link]();

for( j=n-1;j>=p;j--){

ar[j+1]=ar[j];

ar[p]=x;

n++;

void src(){

int sr,pos=0,count=0;

[Link]("enter data to search");

sr=[Link]();

for(int i=0;i<=n;i++){
if(ar[i]==sr){

pos=i;

count++;}

if(count!=0)

[Link]("element found at:"+ pos);

else

[Link]("element not found ");

void del(){

int pos;

[Link](" enter position to delete");

pos=[Link]();

for(int i=pos;i<n-1;i++){

ar[i]=ar[i+1];

n--;

[Link]("element deleted sucessfully");

public static void main(String[] args) {

// TODO code application logic here

NewMain b=new NewMain();

Scanner x=new Scanner([Link]);

for(;;){

[Link]("enter choice");

int ch=[Link]();

switch(ch){
case 1:

[Link]();

break;

case 2:

[Link]();

break;

case 3:

[Link]();

break;

case 4:

[Link]();

break;

case 5:

[Link]();

break;

default:

[Link](0);

🧠 ARRAY ALGORITHMS (Exam Cheat Sheet)

👉 Traversal:

1. Start from i = 0
2. Repeat till i < n

3. Print ar[i]

👉 Insertion:

1. Read position p, element x

2. Shift elements right from n-1 to p

3. Place x at ar[p]

4. Increment n

👉 Deletion:

1. Read position p

2. Shift elements left from p to n-2

3. Reduce n by 1

👉 Search (Linear):

1. Read element x

2. Check each element from i = 0 to n-1

3. If match → element found

4. If no match → not found

👉 Golden Rule 🔥

 Insert → shift right

 Delete → shift left

 Loop always → i < n

You might also like