C++ Assume entries in a linked list are of type struct listrec: struct listrec s
ID: 3740020 • Letter: C
Question
C++
Assume entries in a linked list are of type struct listrec: struct listrec struct listrec next: Write a main) routine in which you create the following linked list: Hend Write a function called istsize that takes a pointer to the start of a linked list and returns the number of elements in the list, and another function called lisssum that also takes a pointer to the start of a linked list and returns the sum of the values of all elements in the list. In your main routine, you need to print out the results of these two functions on computer screenExplanation / Answer
struct listrec {
int value;
struct listrec *next;
}
int main() {
struct listrec *head = NULL;
struct listrec *x3 = new listrec;
x3->value = 30;
x3->next = NULL;
struct listrec *x2 = new listrec;
x2->value = 20;
x2->next = x3;
struct listrec *x1 = new listrec;
x1->value = 10;
x1->next = x2;
head = x1;
}
int listzise(struct listrec *head) {
int count = 0;
while(head != NULL) {
count++;
head = head->next;
}
return count;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.