when we call function bulidlist,then time error
Run time eror when i input in linkedlist
hello @abhinav17
please save ur code here-> https://ide.codingblocks.com/
and share the link with me
#include
using namespace std;
class node{
public:
int data;
node* next;
//constructor
node(int d){
data = d;
next = NULL;
}
};
void insertAtHead(node*&head , int data){
node n = new node(data);
n->next = head;
head = n;
}
int length(node&head){
int len = 0;
while(head !=NULL){
head = head->next;
len +=1;
}
return len ;
}
void insertAtTail(node*&head, int data)
{ if(head == NULL){
head = new node(data);
return ;
}
nodetail = head;
while(tail->next!= NULL){
tail = tail->next;
}
tail->next = new node(data);
return ;
}
void insertInMiddle(node&head , int data,int p){
if(head == NULL || p == 0){
insertAtHead(head,data);
}else if(p >length(head)){
insertAtTail(head,data);
}else{
//insert at middle
// p-1 jump
int jump = 1;
node* temp = head;
while( jump<=p-1){
temp = temp->next;
jump +=1;
}
node *n = new node(data);
n->next = temp->next;
temp->next = n;
}
}
void print(nodehead){
nodetemp = head;
while(temp!= NULL){
cout<data<<" ";
temp = temp->next;
}
}
void buildList(node*&head){
int data;
cin>>data;
while(data =-1){
insertAtTail(head,data);
cin>>data;
}
}
int main() {
node*head = NULL;
buildList(head);
print(head);
return 0;
}
…
how to share link i donot know
go to that link,
paste your code,
click on file option,
then press save button,
a link will be generated,share that link with me
![]()
here it should be
!= in place of =
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.