DELETE FROM LINKED LIST (Q QUERIES)--not getting desired output

link to ques: https://hack.codingblocks.com/contests/c/457/465

#include
using namespace std;

class node{
public:
int data;
node * next;
node(int d)
{
data=d;
next=NULL;
}

};

void print (node*head)
{
while(head!=NULL)
{
cout<data<<" “;
head=head->next;
}
cout<<”\n";
}

void insertathead(node *&head,int data)
{
node * n= new node(data);
n->next=head;
head=n;
}

void insertattail(node *&head,int data)
{
if(head==NULL){
head= new node(data);
return;
}

node * temp=head;
 while(temp->next!=NULL)
 	temp=temp->next;
temp->next=new node (data);
return;

}

void insertlist(node *& head,int s)
{
int data,i=0;
cin>>data;
while(i<s)
{
insertattail(head,data);
cin>>data;
i++;
}
}

ostream & operator<<(ostream & os,node *&head)
{
print(head);
return os;
}

void deletion(node *&head,int key)
{
if(head==NULL)
return;

node * temp = head;
node * pre = NULL;
while(temp !=NULL&& temp->data!=key)
{
	pre=temp;
	temp=temp->next;
}

if(temp==NULL)
	return;
else if(temp==head)
	head=head->next;
else
	pre->next=temp->next;
delete temp;

}

int main()
{
int s,q,x;
cin>>s>>q;
node * head=NULL;
insertlist(head,s);

for (int i=0;i<q;i++)
{
	cin>>x;
	node * temp=head;
	for(int j=0;j<x;j++)
	{
		temp=temp->next;
	}

	deletion(head,temp->data);
	cout<<head;

}




return 0;

}

Shagun save your code on coding block online ide and post the link here,it helps in finding mistakes

the way you are deleting nodes is not correct because nodes can have same values and in that case
your function won’t give correct answer instead u should make a fuction which take argument (head node, the element index u want to delete)
u may refer this :-https://ide.codingblocks.com/#/s/17360
after trying