#include
#include
typedef struct nod{
int info;
struct nod *next;
}node;
node* sortinsert(node *root, int item); //this function is complete
void simpleprint(node* root); //this function is complete
int countnodes (node* root); //to create this function
node* evencopy(node * root); //to create this function
int main()
{
node* head=null;
node* head2 = null;
node *t;
int ch,ele;
head = sortinsert(head, 4);
head = sortinsert(head,6);
head = sortinsert(head,3);
head = sortinsert(head,5);
printf("\nsimple print list 1: ");
simpleprint(head);
printf("\ncount nodes %d", countnodes(head)); //modify the countnodes function to make it work
head2 = evencopy(head); //modify the evencopy function to make it work
printf("\nsimple print after evencopy: ");
simpleprint(head2); //this call should print 4, 6
return 0;
}
void simpleprint(node* root)
{
node* t=root;
while(t!=null)
{
printf("%d ",t->info);
t=t->next;
}
}
node* sortinsert(node* root, int item)
{
node *temp;
node *t;
temp= (node *) malloc(sizeof(node));
temp->info=item;
temp->next=null;
if (root==null || root->info >=item)
{
temp->next = root;
root = temp;
}
else
{
t = root;
while (t->next != null && t->next->info next;
temp->next = t->next;
t->next = temp;
}
return root;
}
///////// the following questions are here: //////////////////
int countnodes (node* root)
{
/*this function takes the head of a linked list and returns the number of nodes available in the linked list. you can use for loops or recursion */
}
node* evencopy(node * root)
{
/*this function takes the head of a linked list and copies all the even numbers to a new linked list and return the
head of the new linked list. note that a number is considered as even if number%2 is 0.
example: passing the head of a linked list containing 3, 4, 5, 6 would return another linked list containing 4, 6 */
}