Create a subdirectory of your home directory named nov09 not

Create a subdirectory of your home directory named nov09 (note the ease) Save your solution in that directory in a file named lists, c. Functions are due at class time on Nov 9. Use my program oct31/linkedlist3. as a starting point. In your program, use each function once and print the return value (if any). Also print the list after each function is called. Write a function that has the head of a list as parameter and returns the length of the list, int length(NODE * head); Write a function that has the head of a list as parameter find which removes the last element of the list. NODE *remove_last(NODE *head); Write a function that returns TRUE (or 1) if the list is in ascending order, and FALSE (or 0) if it Ls not. int in_order(NODE *head); Write a function that removes all odd numbers from the list. NODE *remove_odd(NODE * head);

Solution

Here is the code for you:

int length(node *head)
{
int count = 0;
while(head != NULL)
{
head = head->next;
count++;
}
return count;
}
node *remove_last(node *head)
{
if(head == NULL)
return NULL;
if(head->next == NULL)
return NULL;
node *temp = head;
while(head->next->next != NULL)
head = head->next;
head->next = NULL;
return head;   
}
int in_order(node *head)
{
if(head == NULL)
return 1;
while(head->next != NULL)
if(head->info > head->next->info)
return 0;
return 1;   
}
node *remove_odd(node *head)
{
if(head == NULL)
return NULL;
if(head->next == NULL)
{
if(head->info % 2 == 1)
return NULL;
else
return head;
}
while(head->next->next != NULL)
{
if(head->info % 2 == 1)
head->next->next;
head = head->next;
}
if(head->next->info % 2 == 1)
head->next = NULL;
return head;
}

 Create a subdirectory of your home directory named nov09 (note the ease) Save your solution in that directory in a file named lists, c. Functions are due at cl
 Create a subdirectory of your home directory named nov09 (note the ease) Save your solution in that directory in a file named lists, c. Functions are due at cl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site