Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to simulate an indexed sequence. In an indexed sequence, each it

ID: 3682579 • Letter: W

Question

Write a program to simulate an indexed sequence. In an indexed sequence, each item (node) of an unsorted list is paired with an index (node), where the indices are organized into a sorted list, as shown in Fig. 1. In Fig. 1, each item is a string, while each index is an int beginning at 0. Note that although the indices are sorted, gaps exist between the values of the indices, enabling one to insert additional items between the existing items. The lists are to be represented by original (written by yourself) lists of said items and indices, both encapsulated in a class ClndexedSeq, with member functions to perform the functionally described below. Fig. 1. Indexed Sequence A user can print the items of the sequence, by visiting each of the item nodes in the sequence. In Fig. 1., the items of the sequence are "Make", "my" and "day!" A user can print the full contents of the sequence, including both an item and its associated index, by visiting each of the index nodes in the the sequence. In Fig. 1., the full contents of the sequence are "Make" (0), "my" (2) and "day!" (13). A user can insert a new item, along with a specified index, into the sequence. A user can insert a new item, without a specified index, into the sequence. In this case, the index is taken to be the next ordered index in the sequence. In Fig. 1., index 1 is the next available index. A user can delete the last item of the sequence. Your submission should include a screenshot of the program using the following script.

Explanation / Answer

#include<stdio.h>                                  //for standard input/output functions
#include<stdlib.h>    //for standard library functions
#include<conio.h>                                
//for console input/output functions

struct tele{                                             
//Defining the the telephone directory structure                    char name[20];                                      //To store customer's Name                     
long tel;                                                  //to store the telephone number                  
}a[100];                                                  //Initializing the telephone directory structure with an array

void enter(struct tele a[], int n)          //Function to Enter the data in the telephone directory
{

int i;
  printf(" Now enter the data ");    
for(i=0;i<n;i++)

   {
     printf(" Enter the name:");
     fflush(stdin);                                
//to clear the input stream of all pending input     

     gets(a[i].name);
     printf(" Enter the telephone number:");
     scanf("%ld",&a[i].tel);
   }
}


void sort(struct tele a[],int n)          
//Function to sort the telephone directory as per the name{
int i,j;
struct tele t;
for(i=0;i <n-1;i++)

{
   for(j=i+1;j<n;j++)

{
    if(strcmpi(a[i].name,a[j].name)>0)
   {
     t=a[i];
     a[i]=a[j];
     a[j]=t;
   }
}
}
}

void c_index(struct tele index[], int n, struct tele a[],int asize)   
//For creating the index
{
int i,j;
for(i=0,j=0;i<n;i++,j++)

{
index[j]=a[i];
}
index[j]=a[asize-1];
}


//For indexed search
int i_search(char search[], struct tele index[], int isize, struct tele a[], int asize)
{                         
int i=0,j=0,pos=0;
int high=0,low=0;
if(strcmpi(search,index[isize-1].name)>0||strcmpi(search,index[0].name)<0)

return -1;
while(i<asize)

{
if(strcmpi(search,index[i].name)==0)
{
pos=8*i;
return pos;
}
if(strcmpi(search,index[i].name)

{
low=8*(i-1);
high=8*i;
break;
}
else
{
low=8*i;
high=8*(i+1);
}
i++;
}
while(low<asize)

{
if((strcmpi(search,a[low].name))==0)
return low+1;
else
low++;
}
return -1;
}


int main()

{
char search[20];
int pos,i;
int n;
printf(" Enter the max limit:");
scanf("%d",&n);
enter(a,n);                                              
//Calling the "enter" function
struct tele index[(n/8)+1];
c_index(index,(n/8)+1,a,n);
printf(" Enter the name u wanna search:");
fflush(stdin);
gets(search);
pos=i_search(search,index,(n/8)+1,a,n);  
//Calling the "i_search" function
if(pos==-1)
printf(" Element not found!!");
else
printf("%s found at %d position",search,pos+1);
printf("Telephone number is %ld",a[pos].tel);
getche();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote