Tuesday, August 27, 2013

Codepirate

Posted by at 4:22 AM
CodePirate Admin

Hello, all my user and followers who use this site. this site is specially for the people who like programming and get problems and bugs in that  don't how to deal with them. they are complete guide for students and profession to C++ and C# containing  Oops concepts simple programs that help you peoples,All the programs that are available are completely tested and working with Visual studio 2010. all kinds of program like bubble sort,increment decrement, graphic for console programming. now here all the programs all available go and find out want you wants.

I have just Add new programs that are related Data Structure ,Sorting Techniques ,Go and have Fun..

send us feedback and comment and follow us on this blog. Send us your problems and we will find out problem for you in that.

Circular link list using c++

Posted by at 4:13 AM

Object:

Circular link list using c++
Source Code

#include<iostream.h>
#include<conio.h>
      class  list
         {
         struct node
         {
         int info;
         node *next;
         }*head;
          public:
         list()
           {
           head=NULL;
           }
          void append(int data)
            {
            node *temp,*temp1;
            if(head==NULL)
               {
               temp=new node;
               temp->info=data;
               head=temp;
               temp->next=head;
               }
           else
               {
            temp=head;
            while(temp->next!=head)
               temp=temp->next;
               temp1=new node;
               temp1->info=data;
               temp1->next=head;
               temp->next=temp1;
             }
              }
          void beg_insert(int data)
               {
                node *temp,*temp1;
                 temp=new node;
                 temp1=head;
              if(temp1==NULL)
                cout<<"\n Firstely create using 1 , list not exist";
              else
                 {
                 while(temp1->next!=head)
                   temp1=temp1->next;

                 temp->info=data;
                 temp->next=head;
                 head=temp;
                 temp1->next=head;
                }

                }
            void in_insert(int pos,int data)
                  {
                  node *temp,*t;
                  int a;
                  a=pos;
                  temp=head;
                  while(pos>1)
                {
                temp=temp->next;
                pos--;
                }
               if(temp==NULL)
                   cout<<"\n\t firstely create using 1 , List not exist ";
              else  if(a==0)
                beg_insert(data);

                 else
                   {
                   t=new node;
                   t->info=data;
                   t->next=temp->next;
                   temp->next=t;
                   }
                }
            void del( )
            {
            node *temp,*t;
            temp=head;
            if(temp==NULL)
              cout<<"\n \tList not Exists ";
            else if(temp->next==head)
                {
                delete temp;
                head=NULL;
                }
            else
              {
              t=head->next;
              while(t->next!=head)
                 {
                 t=t->next;
                 temp=temp->next;
                 }
               // t=temp->next->next;
                temp->next=head;
                delete t;
                }
             }


              void beg_del()
             {
              node *temp,*temp1;
              temp=head;
              if(head==NULL)
                cout<<"\n\t Link list has no nodes";
              else
               {
                temp1=head;
                while(temp1->next!=head)
                   temp1=temp1->next;
              head=temp->next;
              temp1->next=head;
              delete temp;
               }
              }
              void mid_del(int pos)
              {
              node *temp,*t;
                int a=pos;
                temp=head;
               while(pos>1)
                  {
                  temp=temp->next;
                   pos--;
                   }
             if(a==1 )
                   beg_del();

             else  if(temp==NULL)
                 cout<<"\n\t List not Exist ..";
              else
               {
               t=temp->next;
               temp->next=temp->next->next;
               delete t;
               }
              }

            void show()
              {
              node *temp;
              temp=head;
              cout<<"\n\t";
              if(temp==NULL)
             cout<<"\n \tList not exist";
              cout<<temp->info;
              temp=temp->next;
              while(temp!=head)
                 {
                 cout<<" - "<<temp->info;
                 temp=temp->next;
                 }
               }
             };
void main()
{
            list l;
            clrscr();
            int ch,pos;
            while(1)
              {
              cout<<"\n\t\tENter your Choice : ";
              cout<<"\n 1: To append\n 2: To insert at Begining\n 3: To insert at any position";
              cout<<"\n 4: To delete\n 5: To del at begining\n 6: To Delete at any position ";
              cout<<"\n 7: To show\n 8: To exit  ";
              cin>>ch;
              if(ch==1)
              {
              cout<<"\n\t Enter data to append : ";
              cin>>ch;
              l.append(ch);
              }
             else if(ch==2)
               {
               cout<<"\n\t Enter element to insert at begining : " ;
               cin>>ch;
               l.beg_insert(ch);
               }
              else if(ch==3)
            {
            cout<<"\nEnter element to insert at specific position  :  ";
            cin>>ch;
            cout<<"\n Enter position  : ";
            cin>>pos;
               l.in_insert(pos,ch);
               }
          else if(ch==4)
             l.del();
          else if (ch==5)
            l.beg_del();
          else if(ch==6)
          {
            cout<<"\n Enter position where u have to delete";
            cin>>pos;
            l.mid_del(pos);
              }
           else if(ch==7)
               l.show();
            else if(ch==8)
              {
              cout<<"\n Press Enter to Exit";
              break;
              }
             else
               cout<<"\n\t Wrong Choice   ";
            }
    getch();
}

Doubly linked list delete – insert

Posted by at 4:01 AM
Object

Doubly linked list delete – insert

Source code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h> 
struct node
{
     struct node *previous;
     int data;
     struct node *next;
}*head, *last; 

void insert_begning(int value)
{
    struct node *var,*temp;
     var=(struct node *)malloc(sizeof(struct node));
     var->data=value;
     if(head==NULL)
     {
         head=var;
         head->previous=NULL;
         head->next=NULL;
         last=head;
     }
     else
     {
         temp=var;
         temp->previous=NULL;
         temp->next=head;
         head->previous=temp;
         head=temp;
     }
} 

void insert_end(int value)
{
     struct node *var,*temp;
     var=(struct node *)malloc(sizeof(struct node));
             var->data=value;
     if(head==NULL)
     {
          head=var;
          head->previous=NULL;
          head->next=NULL;
          last=head;
     }
     else
     {
         last=head;
         while(last!=NULL)
         {
             temp=last;
             last=last->next;
         }
     last=var;
     temp->next=last;
     last->previous=temp;
     last->next=NULL;
     }
}   

int insert_after(int value, int loc)
{
     struct node *temp,*var,*temp1;
     var=(struct node *)malloc(sizeof(struct node));
     var->data=value;
         if(head==NULL)
     {
           head=var;
           head->previous=NULL;
           head->next=NULL;
     }
     else
     {
           temp=head;
           while(temp!=NULL && temp->data!=loc)
           {
                 temp=temp->next;
           }
           if(temp==NULL)
           {
                printf("\n%d is not present in list ",loc);
           }
           else
           {
           temp1=temp->next;
           temp->next=var;
           var->previous=temp; 
          var->next=temp1;
           temp1->previous=var;
           }
     }
     last=head;
     while(last->next!=NULL)
     {
           last=last->next;
     }
}   
int delete_from_end()
{
      struct node *temp;
      temp=last;
      if(temp->previous==NULL)
      {
           free(temp);
           head=NULL;
           last=NULL;
           return 0;
      }
      printf("\nData deleted from list is %d \n",last->data);
      last=temp->previous;
      last->next=NULL;
      free(temp);
      return 0;
} 

int delete_from_middle(int value)
{
    struct node *temp,*var,*t, *temp1;
    temp=head;
    while(temp!=NULL)
    {
        if(temp->data == value)
        {
             if(temp->previous==NULL)
             {
                  free(temp);
                  head=NULL;
                  last=NULL;
                  return 0;
             }
             else
             {
                  var->next=temp1;
                  temp1->previous=var;
                  free(temp);
                  return 0;
             }
        }
        else
        {
              var=temp;
              temp=temp->next;
              temp1=temp->next;
        }
    }
    printf("data deleted from list is %d",value);
}  

void display()
{
     struct node *temp;
     temp=head;
     if(temp==NULL)
      {
         printf("List is Empty");
      }
     while(temp!=NULL)
     {
          printf("-> %d ",temp->data);
          temp=temp->next;
     }
} 

int main()
{
    int value, i, loc;
    head=NULL;
    printf("Select the choice of operation on link list");
    printf("\n1.) insert at begning\n2.) insert at at\n3.) insert at middle");
    printf("\n4.) delete from end\n5.) reverse the link list\n6.) display list\n7.)exit");
    while(1)
    {
          printf("\n\nenter the choice of operation you want to do ");
          scanf("%d",&i);
          switch(i)
          {
                case 1:
                {
                 printf("enter the value you want to insert in node ");
                 scanf("%d",&value);
                 insert_begning(value);
                 display();
                 break;
                 }
                 case 2:
                 {
                 printf("enter the value you want to insert in node at last ");
                 scanf("%d",&value);
                 insert_end(value);
                 display();
                 break;
                 }
                 case 3:
                 {
                 printf("after which data you want to insert data ");
                 scanf("%d",&loc);
                 printf("enter the data you want to insert in list ");
                 scanf("%d",&value);
                 insert_after(value,loc);
                 display();
                 break;
                 }
                 case 4:
                 {
                 delete_from_end();
                 display();
                 break;
                 }
                 case 5:
                 {
                 printf("enter the value you want to delete");
                 scanf("%d",value);
                 delete_from_middle(value);
                 display();
                 break;
                 }
                 case 6 :
                 {
                 display();
                 break;
                 }
                 case 7 :
                 {
                      exit(0);
                      break;
                 }
          }
    }
    printf("\n\n%d",last->data);
    display();
    getch();
}
 
Output 

Find the Uppercase lower case in sentences

Posted by at 3:56 AM


Object:
Find the Uppercase lower case in sentences
Source Code:
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
using namespace std;



void main()
{
      
int word,upper=0,lower=0;
char ch;

cout<<"Enter Sentence"<<endl;
while((ch = getchar()) != '\n')
{
       word=ch;
              if (word >61 && word<87)
           {
                     upper ++;
              }

              if (word >91 && word <127)
              {
                     lower++;
              }
}
      
cout<<"Counted Uppercase Words : \n"<<upper<<"Counted Lowercase words : "<<lower;

}

Output:

Write a program that count the Words in the sentence

Posted by at 3:54 AM


Object:
Write a program that count the Words in the sentence
Source Code:

#include <stdlib.h>
#include <iostream>
#include <stdio.h>
using namespace std;



void main()
{
      
int word=0;
char ch;

cout<<"Enter Sentence"<<endl;
while((ch = getchar()) != '\n')
{

              if (ch == ' ')
           {
                     word ++;
              }
}
      
cout<<"Counted Words : \n"<<word+1;

system("pause");

}

Output:

Popular Posts

Labels

© Codepirate is powered by Blogger - Template designed by Stramaxon - Best SEO Template