Posts

Showing posts from July, 2019

how to check word is palindrome or not using linklist in c++

how to check word is palindrome or not using linklist in c++-> #include<iostream>
using namespace std;

struct node{
    char data;
    node * next=NULL;

    node(char data){
        this->data=data;
        next=NULL;
    }
};
//node* createlinklist(int n);
node* createlinklist(int  n){

    char data;
    cin>>data;
  node * head=NULL;
  if(n==0){

      return head;
  }
  head=new node (data);
  node * tail=head;
  cin>>data;
  while(n>1){
      node * temp=NULL;
      temp=new node (data);
        tail->next=temp;
        tail=temp;
        cin>>data;
        n--;

  }
  return head;

}
bool palindrome(node *&head,node * temp){
    if(temp==NULL&&head==NULL){
        return false;
    }
    if(temp==NULL){
        return true;

    }
   bool k= palindrome(head,temp->next);
   if(k==false){
       return false;
   }
    if(temp->data==head->data){

        head=head->next;
        return true;
    }
    return false;

}

int main(…

how to create basic linklist in c++

how to create basic linklist in c++-->
code->#include<iostream> usingnamespace std; struct node{
int data; node* next; node(int data){ //constructor this->data=data; next=NULL; } }; node * creatlinklist(){ //we crate function for linklist int data; node * head=NULL; cin>>data; if(data!=-1){
head=new node(data); } else{ return head; } node* tail=NULL; tail=head; cin>>data; while(data!=-1){
node *temp=NULL; temp=new node(data); tail->next=temp; tail=temp; cin>>data; }
return head; }
void print(node* head){ //print fucntion while(head){ cout<<head->data<<"-->"; head=head->next; } return; }
int main(){ node* head=creatlinklist(); //function calling print(head); return0; }


how to print reverse of a number in c++

how to print reverse of a number in c++-
you have given a number for eg. 123456789 and have to print 987654321.

c++ code to print reverse a number=#include<iostream>usingnamespacestd;intmain(){int n; cin>>n;int x;for(x=0;n>0;n = n/10){ x = x*10 + n%10; } cout<<x<<endl; }