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

Create a simple linked list program to create a class list containing class node

ID: 3626575 • Letter: C

Question

Create a simple linked list program to create a class list containing
class node {
void *info;
node *next;
public:
node (void *v) {info = v; next = 0; }
void put_next (node *n) {next = n;}
node *get_next ( ) {return next;}
void *get_info ( ) {return info;}
};
Be able to initially fill the list. Provide functions to insert/append nodes and remove
nodes from the linked list. Be able to display the contents of the list.
Write a little driver program with at least 5 values passed in (so that 5 nodes are created)
as you insert/append, delete and display data, showing the programs operation.

Explanation / Answer

#include #include struct node { int data; struct node *next; }*head; void append(int num) { struct node *temp,*right; temp= (struct node *)malloc(sizeof(struct node)); temp->data=num; right=(struct node *)head; while(right->next != NULL) right=right->next; right->next =temp; right=temp; right->next=NULL; } void add( int num ) { struct node *temp; temp=(struct node *)malloc(sizeof(struct node)); temp->data=num; if (head== NULL) { head=temp; head->next=NULL; } else { temp->next=head; head=temp; } } void addafter(int num, int loc) { int i; struct node *temp,*left,*right; right=head; for(i=1;inext; } temp=(struct node *)malloc(sizeof(struct node)); temp->data=num; left->next=temp; left=temp; left->next=right; return; } void insert(int num) { int c=0; struct node *temp; temp=head; if(temp==NULL) { add(num); } else { while(temp!=NULL) { if(temp->datanext; } if(c==0) add(num); else if(cdata==num) { if(temp==head) { head=temp->next; free(temp); return 1; } else { prev->next=temp->next; free(temp); return 1; } } else { prev=temp; temp= temp->next; } } return 0; } void display(struct node *r) { r=head; if(r==NULL) { return; } while(r!=NULL) { printf("%d ",r->data); r=r->next; } printf(" "); } int count() { struct node *n; int c=0; n=head; while(n!=NULL) { n=n->next; c++; } return c; } int main() { int i,num; struct node *n; head=NULL; while(1) { printf(" List Operations "); printf("=============== "); printf("1.Insert "); printf("2.Display "); printf("3.Size "); printf("4.Delete "); printf("5.Exit "); printf("Enter your choice : "); if(scanf("%d",&i)
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote