ASSIGNMENT 01
Singly Linked List implementations
Varda Quraishi(SP18-BCS-169) 9/30/19 DataStructure
, 1. Write a function that deletes all those nodes from a linked list which have even
numbered value in their data part. For instance, if the original list is 1-> 2->3->4->5 -> 6,
then, the updated list should be 2-> 4 -> 6
FUNCTION:
void destroyEvenData() {
if (isEmpty()) { // List is Empty
return;
}
else {
ListNode* temp = start; // Even data in the head node
while (start != NULL && start->data % 2 ==0) {
temp = start;
start = start->next;
delete temp;
}
while (loc != NULL) { // Even data after the head node
if (loc->data % 2 == 0) {
temp = loc;
loc = loc->next;
ploc->next = loc;
delete temp;
}
else { // No even data
ploc = loc;
loc = loc->next;
}
}
}
}
-----------------x----------------x----------------x------------------x------------------x-----------------x-----------------
2. Write a function that prints all nodes of a linked list in the reverse order.
FUNCTION:
void printReverse(){
if (isEmpty()) { // List is Empty
return;
}
else {
while (sloc != NULL) { // While we reach till the
beginning
ploc = loc;
loc->next = ploc;
Singly Linked List implementations
Varda Quraishi(SP18-BCS-169) 9/30/19 DataStructure
, 1. Write a function that deletes all those nodes from a linked list which have even
numbered value in their data part. For instance, if the original list is 1-> 2->3->4->5 -> 6,
then, the updated list should be 2-> 4 -> 6
FUNCTION:
void destroyEvenData() {
if (isEmpty()) { // List is Empty
return;
}
else {
ListNode* temp = start; // Even data in the head node
while (start != NULL && start->data % 2 ==0) {
temp = start;
start = start->next;
delete temp;
}
while (loc != NULL) { // Even data after the head node
if (loc->data % 2 == 0) {
temp = loc;
loc = loc->next;
ploc->next = loc;
delete temp;
}
else { // No even data
ploc = loc;
loc = loc->next;
}
}
}
}
-----------------x----------------x----------------x------------------x------------------x-----------------x-----------------
2. Write a function that prints all nodes of a linked list in the reverse order.
FUNCTION:
void printReverse(){
if (isEmpty()) { // List is Empty
return;
}
else {
while (sloc != NULL) { // While we reach till the
beginning
ploc = loc;
loc->next = ploc;