I need help with this program Suppose you have an array called MyLish which has
ID: 672003 • Letter: I
Question
I need help with this program Suppose you have an array called MyLish which has 20 integers stored in it. You are required to write a program that will read the integers from the array and if the integer number is an even number, you will insert it in a single linked list pointed to the head of the list by headS, if the integer number is an odd number, you will insert it in a double linked list pointed to the head of list by "headD. You will then print out all the numbers in the single linked list and in the You will also need to count how many numbers were in the single linked list double linked list. and how many numbers were in the double linked list. Make sure you have all necessary functions: InitSingle(SglNode Type headS) Initializes the single linked list (4pts) InitDouble(DblNodelType headD) Initializes the double linked list (4 pts) int InsertinSingle(SglNodeType &headS;, int item) Inserts the item in the single linked int Insertin Double(DblNodeType &headD;, int item) Inserts the item in the double linked PrintSinglelist SglNodeType "headS, int singlecount) Prints the values in the single linked PrintDouble ist(DblNodeType "headD, int doublecount) Prints the values in the double list and returns the number of items in the list (10 pts) list and returns the number of items in the list (10 pts) list, along with the number of values in the list (8 pts) linked list, along with the number of values in the list / (8 pts) # include # include #include··My LinkedLists.h" Using namespace std; 36 28 5b int main ) declarations here (4 pts)Explanation / Answer
struct SglNodeType
{
int data;
struct node *next;
};
struct DblNodeType
{
int data;
struct node *next;
struct node *prev;
};
void InitSingle(SglNodeType *headS)
{
struct SglNodeType *temp;
temp = new(struct SglNodeType);
temp->data = NULL;
temp->next = NULL;
headS=temp;
}
void InitDouble(DblNodeType *headD)
{
struct SglNodeType *temp;
temp = new(struct (DblNodeType);
temp->data = NULL;
temp->next = NULL;
temp->prev = NULL;
headD=temp;
}
int InsertInSingle(SglNodeType *&headS,int item)
{
struct SglNodeType *temp;
temp=(struct SglNodeType *)malloc(sizeof(struct SglNodeType));
int count=0;
temp->data=item;
if (headS== NULL)
{
headS=temp;
headS->next=NULL;
}
else
{
temp->next=headS;
headS=temp;
}
while(headS->next!=NULL)
count++;
return count;
}
int InsertInDouble(DblNodeType *&headD,int item)
{
struct DblNodeType *temp;
temp=(struct DblNodeType *)malloc(sizeof(struct DblNodeType));
int count=0;
temp->data=item;
if (headD== NULL)
{
headD=temp;
headD->next=NULL;
headD->prev=NULL;
}
else
{
temp->next=headD;
temp->prev=NULL;
headD=temp;
}
while(headD->next!=NULL)
count++;
return count;
}
void PrintSingleList(SglNodeType *&headS,int doubleCount)
{
SglNodeType *temp=headS;
int count=0;
while(temp->next!=NULL)
{
std::cout<<temp->data;
count++;
}
std::cout<<"Values in list"+count;
}
void PrintDoubleList(DblNodeType *&headD,int doubleCount)
{
DblNodeType *temp=headD;
int count=0;
while(temp->next!=NULL)
{
std::cout<<temp->data;
count++;
}
std::cout<<"Values in list"+count;
}
int main()
{
SglNodeType *headS=NULL;
DblNodeType *headD=NULL;
InitSingle(headS);
InitDouble(headD);
int MyList[20]={22,11,4,3,65,78,69,12,38,43,883,25,41,76,82,19,16,432,582,120};
int countS=0,countD=0;
for (int i=0;i<20;i++)
{
if((MyList[i])%2==0)
countS=InsertInSingle(headS,MyList[i]);
else countD=InsertInDouble(headD,MyList[i]);
}
PrintSingleList(headS,countS);
PrintDoubleList(headD,countD);
}