All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Thursday, 27 March 2014

Merging two Accending Arrays

//Merging two Accending Arrays
#include<iostream.h>
int main()
{
int a[50],b[50];
int i,j,k,m,n;
cout<<"enter no of elements in A ";
cin>>m;
for(i=0;i<m;i++)
{
cin>>a[i];
}
cout<<"enter no of elements in B ";
cin>>n;
for(j=0;j<n;j++)
{
cin>>b[j];
}
//////////////////////////////////////
int s=m+n;
int p=0;j=0;
label:i=p;
for(i=p;i<m;i++)
{
if(b[j]<a[i])
{
for(k=m;k>i;k--)
{
a[k]=a[k-1];
}
a[i]=b[j];
m++;
j++;
p=i+1;
goto label;
}
}

if(m<s)
{
 for(i=j;i<=n;i++,j++)
 {
  a[m]=b[j];
  m++;
 }
}
for(i=0;i<s;i++)
{
cout<<a[i]<<" ";
}
return 0;
}

Saturday, 15 March 2014

Creating Nodes in Singly Linked List Using Structure.

//Creating Nodes in Singly Linked List Using Structure.
#include<iostream.h>
using namespace std;
struct node
{
 char info;
 node *link;
};
int main()
{
 node *start,*p,*temp;
 start=p=NULL;
 char ch;
 do
 {
  char item;
  cout<<"Input Element to info :";
  cin>>item;
  temp=new node;
  temp->info=item;
  temp->link=NULL;
  if(start==NULL)
start=temp;
  else
p->link=temp;
  p=temp;
  cout<<"Create More Nodes y or n :";
  cin>>ch;
 }while(ch=='y');
 //printing nodes
 p=start;
 while(p)
 {
  cout<<p->info;
  p=p->link;
 }
return 0;
}

Thursday, 13 March 2014

Creation of linklist by using the concept of Parallel Array

//Creation of linklist by using the concept of Parallel Array
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int info[10],link[10],item,p,i;
for(i=1;i<10;i++)
{link[i]=i+1;}
link[i]=0;
int start=0,free=1,node=0;
char ch;

do
{
if(start==0)
{
start=free;
cout<<"enter the item to insert ";
cin>>item;
info[start]=item;
free=link[free];
link[start]=0;
node++;
}
      else
{
p=start;
while(link[p]!=0)
{p=link[p];}
link[p]=free;
p=link[p];
cout<<"enter the no to be insert ";
cin>>item;
info[p]=item;
free=link[free];
link[p]=0;
node++;
}
cout<<"wants to continue y or n: ";
cin>>ch;
}while(ch=='y');

cout<<"created linklist are ";
for(i=1;i<=node;i++)
cout<<info[i]<<"  ";
return 0;
getch();
}

Thursday, 6 March 2014

Creation Of A Node In Singly Link List using Structure in C

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
//-------------------------------------------------
struct node
{
int data;
struct node *next;
}*start=NULL;
//-------------------------------------------------

void create()
{
char ch;
 do
 {
  struct node *new_node,*current;

  new_node=(struct node *)malloc(sizeof(struct node));

  printf("\n Enter the data : ");
  scanf("%d",&new_node->data);
  new_node->next=NULL;

  if(start==NULL)
  {
  start=new_node;
  current=new_node;
  }
  else
  {
  current->next=new_node;
  current=new_node;
  }

 printf("\n Do you want to creat another : ");
 ch=getche();
 }while(ch!='n');
}
//------------------------------------------------------------------

void display()
{
struct node *new_node;
 printf("The Linked List : \n");
 new_node=start;
 while(new_node!=NULL)
   {
   printf("%d->",new_node->data);
   new_node=new_node->next;
   }
  printf(" NULL");
}
//----------------------------------------------------
void main()
{
clrscr();
create();
display();
getch();
}
//----------------------------------------------------