Assignment Link List
Assignment Link List
Spring 2014
Assignment 4
Singly Link List
[email protected]
Objective
●Link List
Question No. 1
Write the following Function:-
1. InsertAtend(int); This function takes an integer as a parameter
adds a new node at the end of the list.
2. InsertAtstart(int); This function take an integer as parameter add a
new node at the start of the list.
3. InsertAfter(int, int); This function take two integers as a parameter
and insert a new node after first integer value.
1->2->3->4->5
InsertAfter(3,6);
1->2->3->6->4->5
4. InsertBefor(int,int); this function take two integer as parameter
and insert new node after first integer value.
1->2->3->4->5
InsertBefor (3,6);
1->2->6->3->4->5
5. DeleteAtend(); this function delete the last node of the list.
6. DeleteAtstart(); this function delete the first node of the list.
7. DeleteAnyloction(int); this function take one integer as parameter
and delete this integerlocation node.
1->2->6->3->4->5
DeleteAnyloction(3);
1->2->3->4->5
8. DeleteBefore(int); this function take one integer as parameter and
delete before this integerlocation node.
1->2->6->3->4->5
DeleteBefore (3);
1->2->3->4->5
9. DeleteAfter(int); this function take one integer as parameter and
delete After this integerlocation node.
1->2->6->3->4->5
DeleteAfter (3);
1->2->6->3->5
10. SwapanyTwoNodeData(int,int); this function take two integer as
parameter and swap these node data.
1->2->6->3->4->5
SwapanyTwoNodeData (2,4);
1->3->6->2->4->5
15. DeleteanyNode(int);
1->2->6->3->2->4->5
If the integer is 2
1->6->3->4->5
Question No. 2
Write a function to find the 5th element from a singly link list from the end (not
from Head) in the one pass.
Question No. 3
Write a Function append the last n node of a link list to the beginning of the list.
e.g : 1->2->3->4->5->6
if n=2
5->6->1->2->3->4
Question No. 4
Write a function to swap the consecutive two elements of a list. Such as,
if list is “a->b->c->d->e->NULL” then after calling the function the list will be “b->a-
>d->c->e->NULL”.
Question No. 5
Question No. 6
Write a function take two list as parameters and return a 3rd list as:
Suppose:
L1 = 1->2->3->4
L2 = 5->6->7
Make L3 as:
1->5->2->6->3->7->4
Question No. 7
Write a function take two integer link lists and Add these lists and store in the 3 rd
link list.
1->2->-3->4->5->6->7->8->9->0
1->2->-3->4->5->6->7->8->9->0
2->4->6->9->1->3->5->7->8->0
Question No. 8
Write a function take two link lists as a parameter and merge them in the 3 rd list.
L1: 2->4->6->8->10
L2: 1->3->5->7->9
L3: 1->2->3->4->5->6->7->8->9->10
Question No. 9
Write a function that takes two sorted lists and take the union of those lists in
another list, then return the new list from the function.
L1: 1->2->4->6->8->10
L2: 1->3->4->5->7->9
List Union(List L1, List L2);
L3: 1->2->3->4->5->6->7->8->9->10
Question No. 10
Write a function that takes two sorted lists and take their Intersection of those
lists in another list, then return the new list from the function.
L1: 1->2->4->5->6->8->10
L2: 1->3->4->5->7->9
L3: 1->4->5
Question No. 11
1->2->5->6->4->11->10->3
Void Sort();
1->2->3->4->5->6->10->11