This is the code:
#include
using namespace std;
#include <bits/stdc++.h>
class Node {
public:
int x;
Node* next;
};
Node* fun(int x,Node *p){
cout<<“231”;
Node *u,*temp;
u=p;
temp->x=x;
temp->next=NULL;
if(p==NULL){
p=temp;
}
else{
while(u->next!=NULL){
u=u->next;
}
u->next=temp;
}
return p;
}
Node* even(Node *p){
Node *hp=p;
Node *ht=p;
Node *eh=hp->next;
Node *et=hp->next;
Node *temp=et->next;
hp->next=NULL;
et->next=NULL;
while(temp){
hp->next=temp;
ht=temp;
temp=temp->next;
if(temp==NULL){
break;
}
ht->next=NULL;
eh->next=temp;
et=temp;
temp=temp->next;
if(temp=NULL){
break;
}
et->next=NULL;
}
ht->next=eh;
return hp;
}
void display(Node *p){
Node *q=p;
while(q!=NULL){
cout<x<<" ";
q=q->next;
}
}
int main() {
int n;
Node *p=new Node();
cin>>n;
Node *h=new Node();
Node *t=new Node();
for(int i=0;i<n;i++){
int x; cin>>x;
t=fun(x,p);
}
h=even(t);
display(h);
return 0;
}
ERROR:
/bin/run.sh: line 4: 18 Segmentation fault (core dumped) ./exe