On terminal ,code is giving correct output

it is not give write output on CB code editor while submitting

Just display the sorted linked list in the end

#include<bits/stdc++.h> using namespace std; class node {public: int data; node *next; }; node * getnode() {return new node; } int main() {int n,i; cin>>n; node *head,*temp,*curr,*prev; head=getnode(); cin>>head->data; head->next=NULL; n–; curr=head; while(n–) {cin>>i; curr=head; prev=NULL; temp=getnode(); temp->data=i; temp->next=NULL; while(curr!=NULL) {if(curr->data>i) {if(curr==head) {temp->next=head; head=temp; } else {temp->next=curr; prev->next=temp; } break; } prev=curr; curr=curr->next; } if(curr==NULL) prev->next=temp; } while(head!=NULL) {cout<data<<" ";head=head->next; } return 1; }

Create separate functions for building the linked list and then printing it.
Check out my code and tell me if you are able to understand it -

there is nothing to understand ,it is simple but why it showing error in cb code editor

Cool if you have understood my code. And it is not showing any error. Its correct.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.