Write a c program languageof lists using an array based impl
Write a c program language,of lists using an array based implementation which includes operations of list like:-
1.Locate
2.Next
3.Previous
4.Retrieve
5.Makenull
6.Insert
7.Delete
8.printlist
Note:Accept a array of length more than 10.
Take input as integers.
Solution
#include<stdio.h>
 #include<conio.h>
 #define MAX 20
 //maximum no of elements in the list//user defined datatypes
 struct{
 int list[MAX];
 int element;
 int pos;
 int length;
 }l;
 enum boolean
 { true, false };
 typedef enum boolean boolean;
int menu(void);
 void create(void);
 void insert(int, int);
 void delet(int);
 void find(int);
 void display(void);
 boolean islistfull(void);
 islistempty(void);
void main()
 {
 int ch;
 int element;
 int pos;
 l.length = 0;
 while(1)
 {
 ch = menu();
 switch (ch)
 {
 case 1:
 l.length = 0;
 create();
 break;
 case 2:
 if (islistfull() != true)
 {
 printf(\"\\tEnter the New element : \");
 scanf(\"%d\", &element);
 printf(\"\\tEnter the Position : \");
 scanf(\"%d\", &pos);insert(element, pos);
 }
 else
 {
 printf(\"\\tList if Full. Cannot insert\");
 printf(\"\ Press any key to continue...\");
 getch();
 }
 break;
 case 3:
 if (islistempty() != true)
 {
 printf(\"Enter the position of element to be deleted : \");
 scanf(\"%d\", &pos);
 delet(pos);
 }
 else
 {
 printf(\"List is Empty.\");
 printf(\"\ Press any key to continue...\");
 getch();
 }
 break;
 case 4: printf(\"No of elements in the list is %d\", l.length);
 printf(\"\ Press any key to continue...\");
 getch();
 break;
 case 5: printf(\"Enter the element to be searched : \");
 scanf(\"%d\", &element);
 find(element);
 break;
 case 6:display();
 break;
 case 7:exit(0);
 break;
 default: printf(\"Invalid Choice\");
 printf(\"\ Press any key to continue...\");
 getch();
 }
}}
 //function to display the list of elements
 int menu()
 {
 int ch;
 clrscr();
 printf(\"\ \\t\\t********************************************\ \");
  printf(\"\\t\\t******LIST Implementation Using Arrays******\ \");
 printf(\"\\t\\t********************************************\ \ \");
  printf(\"\\t1. Create\ \\t2. Insert\ \\t3. Delete\ \\t4. Count\ \\t5. Find\ \\t6. Display\ \\t7.
 Exit\ \ \\tEnter your choice : \");
 scanf(\"%d\", &ch); printf(\"\ \ \");
 return ch;
 }//function to create initial set of elements
 void create(void)
 {
 int element;
 int flag=1;
 while(flag==1)
 { printf(\"Enter an element : \");
 scanf(\"%d\", &element);
 l.list[l.length] = element;
 l.length++;
 printf(\"To insert another element press \'1\' : \");
 scanf(\"%d\", &flag);}}
 //function to display the elements in the list
 void display(void)
//function to insert the given element at specified positionvoid insert(int element, int pos){
 int i;
 if (pos == 0)
 {
 printf(\"\ \ Cannot insert at zeroth position\");
 getch();
 return;
 }
 if (pos-1 > l.length)
 {
 printf(\"\ \ Only %d elements exit. Cannot insert at %d postion\", l.length, pos);
 printf(\"\ Press any key to continue...\");
 getch();
 }
 else
 {
 for (i=l.length; i>=pos-1; i--)
 {
 l.list[i+1] = l.list[i];}l.list[pos-1] = element;
 l.length++;
 }}
 //function to delete the element at given position
 void delet(int pos)
 {
 int i;if(pos == 0)
 { printf(\"\ \ Cannot delete at zeroth position\");
 getch();
 return;
 }
 if (pos > l.length)
 {
 printf(\"\ \ Only %d elements exit. Cannot delete\", l.length, pos);
 printf(\"\ Press any key to continue...\");
 getch();
 return;
 }
 for (i=pos-1; i<l.length; i++){l.list[i] = l.list[i+1];}l.length--;
 }//function to find the position of the given element, if existsvoid find(int element){int i;int flag = 1;
 
 for (i=0; i<l.length; i++)
 {
 if(l.list[i] == element)
 {
 printf (\"%d exists at %d position\",element, i+1);
 flag = 0;
 printf(\"\ Press any key to continue...\");
 getch();
 break;
 }}
 if(flag == 1)
 {
 printf(\"Element not found.\ Press any key to continue...\");
 getch();
 }}
 //function to check whether the list is full or not
 boolean islistfull(void)
 {
 if (l.length == MAX)return true;elsereturn false;}
 //function to check whether the list is empty or not
 boolean islistempty(void)
 {if (l.length == 0)return true;elsereturn false;}




