Created
March 19, 2020 09:54
-
-
Save manaswinidas/7e822fa215a543069c5d547c1ac23f75 to your computer and use it in GitHub Desktop.
Program to use array as Linked List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class ArrayLL{ | |
static char choice; | |
static int arr[]={2,3,4,5,6}; | |
public static void deletebyIndex(int index){ | |
arr[index]=0; | |
System.out.println("Element deleted"); | |
} | |
public static void insertElement(int value){ | |
for(int i=0;i<arr.length;i++){ | |
if(arr[i]==0){ | |
arr[i]=value; | |
break; | |
} | |
} | |
System.out.println("Element inserted"); | |
} | |
public static void getArray(){ | |
System.out.println("Array Elements:"); | |
for(int i=0;i<arr.length;i++){ | |
System.out.print("\t"+arr[i]); | |
} | |
} | |
public static void main(String[] args){ | |
Scanner sc=new Scanner(System.in); | |
do{ | |
System.out.println("1. Delete element"); | |
System.out.println("2. Insert element"); | |
System.out.println("3. Print array"); | |
int ch=sc.nextInt(); | |
switch(ch){ | |
case 1: | |
System.out.println("Enter index:"); | |
int index=sc.nextInt(); | |
deletebyIndex(index); | |
break; | |
case 2: | |
System.out.println("Enter value:"); | |
int value=sc.nextInt(); | |
insertElement(value); | |
break; | |
case 3: | |
getArray(); | |
break; | |
} | |
System.out.println("\nDo you want to continue?[y/n]"); | |
choice=sc.next().charAt(0); | |
}while(choice!='n'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment