Lab 14: Linked Lists

Today you will be writing some functions for linked lists.

We have given you a snippet of code, which includes the struct for you linkedlist.

The main handles all of the calling and user input.

You have to complete two functions to complete the task.

1) Write a function which displays the elements in the linked list that are at even positions (1 Point)

2) Write a function which accepts a number and a position in the linked list and insert the the number in the linked list after that position. (2 Points)

NOTE: All positions and indices start from 0.

Do not change anything in the main.

Task 1:

You have to insert your code in the empty function of DisplayEvenList

 Assume the head is at index 0. You have to display the elements (node data) in the list that are at even positions.

 

Sample:

If the Linked list has these elements:

5 2 9 10 50 -1

The Even elements in the Linked List: 5 9 50

5 is at position 0

9 is at position 2

50 is at position 4

Task 2:

You have to write your code in the empty function of insertToList

 Assume the head is at index 0, and you enter a valid position less than the size of the list.

 

 The function uses the user input of data and position.

 You have to insert the data in the linked list after the "position" index.

 

Sample:

If the Linked list has these elements:

5 2 9 10 50 -1

Enter the position for the new element: 3

Enter the value you want to enter: 67

The new linked list should look like:

5 2 9 10 67 50 -1