#include "arr.h"
arr.h file:
[code]
//arr.h
#include <iostream>
#include <cstring>
#include <cctype>
constint SIZE = 5; //size of the array of head pointers
struct node
{
int data;
node * next;
};
/* These functions are already written and can be called to test out your code */
void build(node * head[]); //supplied
void display(node * head[]); //supplied
void destroy(node * head[]); //supplied
/* *****************YOUR TURN! ******************************** */
//Write your function prototype here:
int sum(node * head[]);
void removeTwo(node * head[]);
#include <iostream>
#include "arr.h"
usingnamespace std;
int main()
{
node * head[SIZE] = {0,0,0,0,0};
build(head);
display(head);
//PLEASE PUT YOUR CODE HERE to call the function assigned
int total = sum(head);
//cout << "Sum of array of linked list is:" << endl;
cout << total << '\n' << endl;
removeTwo(head);
//cout << "The array of linked list after removing two: " << endl;
display(head);
destroy(head);
return 0;
}
What is the error message? If it is something like "undefined reference" about the "other functions" you are probably not linking the supplied .o file correctly.
The if clause on line 35 in removeTwo(...) is certainly wrong.
1 2 3 4 5 6 7 8 9 10 11 12
if(temp == head[i])
{
if(head[i]->next)
{
temp = head[i]->next;
head[i]->next = temp->next;
delete temp;
temp = head[i];
}
else
??? // Problem here: What to do with the content of head[i]?
}