Question: I am getting error in this code. Please help. Code: #include #include void insertAtBegining(int num){ //Creating a node struct node *temp; temp= (struct node *)malloc(sizeof(struct

I am getting error in this code. Please help.

Code:

#include #include

void insertAtBegining(int num){ //Creating a node struct node *temp; temp= (struct node *)malloc(sizeof(struct node)); //Swapping this to be the head node temp->data=num; temp->next=head; head=temp; }

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; if(right==NULL) { add(num) } else { 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->datadatanext; } if(c==0) add(num); else if(c

int delete(int num)

{

struct node * temp, * prev; //Will store reference to the last matched element found,////And the corresponding prev node struct node * nodeFound = NULL; struct node * nodeFoundPrev = NULL;

temp = head;

while (temp != NULL) {

if (temp - > data == num)

{ nodeFound = temp; nodeFoundPrev = prev; } else

{ prev = temp; temp = temp - > next; } } //Process only if atleast one match has been found if (nodeFound != NULL) {

//After the last matched node, found and strored in nodeFound if (nodeFound == head) { head = nodeFound - > next; free(nodeFound); return 1;

} else

{ nodeFoundPrev - > next = nodeFound - > next; free(nodeFound);

return 1; } } 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)<=0){ printf("Enter only an Integer "); exit(0); } else { switch(i)

{ case 1: printf("Enter the number to insert : "); scanf("%d",&num); // insert(num); append(num); break; case 2: if(head==NULL) { printf("List is Empty "); } else { printf("Element(s) in the list are : "); } display(n); break; case 3: printf("Size of the list is %d ",count()); break; case 4: if(head==NULL) printf("List is Empty "); else{ printf("Enter the number to delete : "); scanf("%d",&num); if(delete(num)) printf("%d deleted successfully ",num); else printf("%d not found in the list ",num); } break; case 5: return 0; default: printf("Invalid option "); } } } return 0; }

Error:

In function 'void insertAtBegining(int)':

7:69: error: invalid application of 'sizeof' to incomplete type 'insertAtBegining(int)::node'

9:27: error: invalid use of incomplete type 'struct insertAtBegining(int)::node'

6:30: error: forward declaration of 'struct insertAtBegining(int)::node'

10:27: error: invalid use of incomplete type 'struct insertAtBegining(int)::node'

6:30: error: forward declaration of 'struct insertAtBegining(int)::node'

10:34: error: 'head' was not declared in this scope In function 'void append(int)':

31:12: error: 'add' was not declared in this scope In function 'void insert(int)':

100:21: error: 'count' was not declared in this scope At global scope:

109:5: error: expected unqualified-id before 'delete'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!