LL13

#include<iostream>
using namespace std;
struct node
{
  int data;
  struct node *next;
}*head,*temp;
bool search(int a)
{
  temp=head;
  while(temp!=0)
  {
    if(a==temp->data)
      return 1;
    temp=temp->next;
  }
  return 0;
}
int main()
{
  int n,X;
  bool status;
  cin>>n;
  head=0;
  while(n--)
  {
    struct node* new_node =(struct node*) malloc(sizeof(struct node));
    cin>>new_node->data;
    new_node->next=0;
    if(head==0)
    {
      head=temp=new_node;
    }
    else
    {
      temp->next=new_node;
      temp=new_node;
    }
  }
  cin>>X;
  status=search(X);
  if(status==1)
  {
    cout<<"Yes";
  }
  else
    cout<<"No";
  return 0;
}
 
 

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. #include
    using namespace std;
    struct node
    {
    int data;
    struct node *next;
    }*head,*temp;
    bool search(int a)
    {
    temp=head;
    while(temp!=0)
    {
    if(a==temp->data)
    return 1;
    temp=temp->next;
    }
    return 0;
    }
    int main()
    {
    int n,X;
    bool status;
    cin>>n;
    head=0;
    while(n--)
    {
    struct node* new_node =(struct node*)malloc(sizeof(struct node));
    cin>>new_node->data;
    new_node->next=0;
    if(head==0)
    {
    head=temp=new_node;
    }
    else
    {
    temp->next=new_node;
    temp=new_node;
    }
    }
    cin>>X;
    status=search(X);
    if(status==1)
    {
    cout<<"Yes";
    }
    else
    cout<<"No";
    return 0;
    }

    ReplyDelete
  3. #include
    using namespace std;
    struct node
    {
    int data;
    struct node*next;
    }*head,*temp;
    bool search(int a)
    {
    temp=head;
    while(temp!=0)
    {
    if(a==temp->data)
    return 1;
    temp=temp->next;
    }
    return 0;
    }
    int main()
    {
    int N,x;
    bool status;
    cin>>N;
    head=0;
    while(N--)
    {
    struct node* new_node=(struct node*)malloc(sizeof(struct node));
    cin>>new_node->data;
    new_node->next=0;
    if(head==0)
    {
    head=temp=new_node;
    }
    else
    {
    temp->next=new_node;
    temp=new_node;
    }
    }
    cin>>x;
    status=search(x);
    if(status==1)
    {
    cout<<"Yes";
    }
    else
    cout<<"No";
    return 0;
    }

    ReplyDelete

SRM ELAB SOLUTUONS   DATA-STRUCTURE                                                                             **IF THE PROGRAM DON...