Answer to Question #12244 in C++ for Bassam

Question #12244
Write a program to copy the content of the following array to a dynamic single linked list, and write a function to delete every node has an even value in its data ?
1
Expert's answer
2012-07-26T08:50:18-0400
struct node{
int value;
struct node* next;
};
node* root = new node;

void toList(int* array, int size){
root->value = array[0];
root->next = NULL;
node* temp = root;
for(int i = 1; i < size; i++){
node* n = new node;
n->next = NULL;
n->value = array[i];
temp->next = n;
temp = n;
}
}

void remove(){
node* temp = root;
while(temp->next != NULL){
if(temp->next->value % 2 == 0){
temp->next= temp->next->next;
}
else
temp = temp->next;
}
if(root->value % 2 == 0)
root = root->next;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS