can someone tell what is error in the code.

#include < iostream >
using namespace std;
struct node
{
int data;
struct node *next;
};

int main()
{    
 int a,d;    
  node *head=new node;    
node *tail=new node;    
 node *temp=new node;    
  cin>>a;    
  int k;    
  a++;    
  k=a;    
  while(a--)    
  {   
    cin >> d;    
    if(--k==a)   
    {   
      head->data=d;     
      tail=head;    
      k++;    
    }    
   else    
    {    
      node *temp=new node;    
      temp->data=d;
          tail->next=temp;    
      temp->next=NULL;    
      tail=temp;    
      }    
  }    
  temp=head;
  cin>>d;    
  while(d)    
  {    
    head=head->next;    
    d--;    
  }    
  temp=head;    
  cout<<"\nLinked List\n";    
  while(temp->next!=NULL)    
  {    
    cout<<"->"<<temp->data;    
    temp=temp->next;    
  }    
	return 0;
}

Another probable contest question. What is the question here? Without a question how can we say where you are going wrong?

1 Like

Don’t just paste the code here and ask for a correction. Explain what are you trying to do and what’s the problem that you are facing.

1 Like

The problem is i dont know where did the program go wrong…its not compiling and according to my knowledge the program logic is right.