Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include using namespace std; struct noodle { int student; float gpa; noodle *ne

ID: 3530492 • Letter: #

Question

#include using namespace std; struct noodle { int student; float gpa; noodle *next; }; void insert(int item, float gpa1, noodle * &tail) ; void printlist(noodle *head); int main() { noodle *head, *tail; head = new noodle; tail = new noodle; head->next = tail; head->student=0; for(int i=1; i<=10; i++) { // inserting 10 students float gpa1= (rand()@)/10.0 ; insert(2*i, gpa1, tail); printlist(head); } system("pause"); return 0; } void insert(int item, float gpa1, noodle *&tail) //forgetting the & means I wasted an hour { // we are pushing new information into the tail noodle *t = new noodle; // put in new student information tail->student=item; tail->gpa=gpa1; tail->next=t; tail=t; t->next=NULL; } void printlist(noodle *head) { noodle *t=head->next; while (t->next!=0) { cout <<" Student id "<<t->student<<" with gpa "<<t->gpa<<endl; t= t->next; } cout<<endl; }

Explanation / Answer


check this answer rate with 5 star and rate it first.

Here iam deleting node from the head.


#include<iostream>

#include<cstdlib>

using namespace std;

struct noodle { int student; float gpa; noodle *next; };

void insert(int item, float gpa1, noodle * &tail) ;

void printlist(noodle *head);


void insert(int item, float gpa1, noodle *&tail){

// put in new student information

tail->student=item;

tail->gpa=gpa1;

noodle *t = new noodle;

tail->next=t;

tail=t;

t->next=NULL;

}

void printlist(noodle *head) {

noodle *t=head->next;

while (t->next!=NULL) {

cout <<" Student id "<<t->student<<" with gpa "<<t->gpa<<endl;

t= t->next;

}

cout<<endl;

}


noodle * deletenode(noodle * head){


noodle * temp = head;

head = head->next;

free(temp);

return head;


}


int main() {

noodle *head, *tail;

head = new noodle;

tail = new noodle;

head->next = tail;

head->student=0;

head->gpa = 0.0;

int gpal = 0;

for(int i=1; i<=10; i++) {

// inserting 10 students float

gpal= (rand())/10.0 ;

insert(i, gpal, tail);

printlist(head);

}


for(int i=1; i<=10; i++) {

// inserting 10 students float

head = deletenode(head);

printlist(head);

}

system("pause");

return 0;

}