Fill the list with the whole elements, adding elements: a) linked list, insert a
ID: 3840777 • Letter: F
Question
Fill the list with the whole elements, adding elements: a) linked list, insert at beginning, insert at end, insert at position; b) sort list: insert, according to the principle of soiling; and ensure output on the screen; remove an element from the list with the given position pos (the value pos to be entered by the program user); output functions Size, Empty and Full results; carry out with list the following activities and ensure output of the results: a) count the pairs of elements in the list; b) count elements that are equal to zero; c) count negative elements in the list; d) find the number of elements that belong to the interval (-10; 10].Explanation / Answer
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
class LinkedListArray
{
public static void main(String args[])
{
int post,x,i,j;
Scanner scan = new Scanner(System.in);
int LinkedListArray[] = new int[20];
System.out.println("Size of Array:" +LinkedListArray.length);
System.out.println(" Enter the size of array:");
int n = scan.nextInt();
int ar[] = new int[n+1];
System.out.println(" Enter the elemenets to be inserted:");
for(i=0; i<n; i++)
{
ar[i] = scan.nextInt();
}
System.out.println(" Enter the Positon for insertion:");
post = scan.nextInt();
System.out.println(" Enter element to insert in position:");
x = scan.nextInt();
for(i = (n-1); i >= (post-1); i--)
{
ar[i+1] = ar[i];
}
ar[post-1] = x;
System.out.println(" After inserting:");
for(i = 0; i < n; i++)
{
System.out.print(ar[i]+" ");
}
System.out.print(ar[n]);
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (ar[i] > ar[j])
{
int temp = ar[i];
ar[i] = ar[j];
ar[j] = temp;
}
}
}
System.out.println(" Sorted Elements");
for(i=0;i<n+1;i++)
{
System.out.print(ar[i]+" ");
}
}
}
output
Size of Array:20
Enter the size of array: 5
Enter the elemenets to be inserted: 12 -34 22 45 67
Enter the Positon for insertion: 4
Enter element to insert in position: 56
After inserting:
12 -34 22 56 45 67
Sorted Elements
-34 12 22 45 56 67
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.