Sunday, December 30, 2012
Saturday, June 2, 2012
//fms
//multiple stack
#include<stdio.h>
#include<conio.h>
int st[20],size[20],lb,ub,t[10],j,d,n;
void setst(int i)
{
if(i==1)
{
lb=0;
ub=(n-1);
//printf("\n%d %d",lb,ub);
}
else
{
lb=(i-1)*n;
ub=(i)*n-1;
//printf("\n%d %d",lb,ub);
}
}
void initialise()
{
int p;
for(p=0;p<10;p++)
{
setst(p+1);
t[p]=lb;
}
}
void push(int itm,int i)
{
int top;
setst(i);
top=t[i-1];
if(top>ub)
{
printf("\nStack %d full!",i);
return;
}
else
{
st[top]=itm;
top++;
t[i-1]=top;
}
}
void pop(int i)
{
int top,itm;
setst(i);
top=t[i-1];;
if(top<lb)
printf("\nStack %d empty!",i);
else
{
itm=st[top];
st[top]=0;
top--;
t[i-1]=top;
}
}
void disp(int i)
{
int top,k;
setst(i);
top=t[i-1];
for(k=top-1;k>=lb;k--)
{
printf("\n%d\n",st[k]);
}
}
void main()
{
int i,index,itm,ch,w;
clrscr();
printf("\nEnter size of array:");
scanf("%d",&j);
printf("\nEnter how many stack?");
scanf("%d",&d);
n=(j/d);
initialise();
do
{
printf("\nEnter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nEnter item:");
scanf("%d",&itm);
printf("\nEnter stack number:");
scanf("%d",&i);
setst(i);
push(itm,i);
break;
case 2:printf("\nEnter stack number:");
scanf("%d",&i);
pop(i);
break;
case 3:printf("\nIndex of stack:");
scanf("%d",&i);
disp(i);
break;
case 4:dispall(d);
break;
case 5:exit(0);
}
}while(1);
getch();
}
dispall(int d)
{
int k,index,i;
for(index=1;index<=d;index++)
{
printf("Stack number is %d\n",index);
setst(index);
for(k=ub;k>=lb;k--)
{
printf("\n%d\n",st[k]);
}
}
}
DATA STRUCTURES.-circular linked list
//fms
//program to implement circular linked list
#include<malloc.h>
#include<conio.h>
#include<stdio.h>
struct node
{
int info;
struct node *link;
}*last;
typedef struct node *nod;
void main()
{
int ch,n,m,i,pos,c,k,a,ch1;
last->link=last;
clrscr();
printf("\nMENU\n1.create\n2.dispaly in sorted order\n3.insert\n 1.front\n 2.end\n 3.any\n4.delete\n 1.front\n 2.end\n 3.any\n5.modify\n6.exit");
do
{
printf("\nEnter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nEnter the number of nodes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter element:");
scanf("%d",&m);
create_l(m);
}
break;
case 2:printf("\nElements in sorted order are.....\n");
display();
break;
case 3:do
{
printf("\nEnter your choice:");
scanf("%d",&c);
switch(c)
{
case 1:printf("\nEnter the element");
scanf("%d",&m);
insertf(m);
break;
case 2:printf("\nEnter the element");
scanf("%d",&m);
inserte(m);
break;
case 3:printf("\nEnter the element");
scanf("%d",&m);
printf("\nEnter key:");
scanf("%d",&k);
inserta(k,m);
break;
default:printf("invalid choice");
}
printf("\nDo you need 2 continue 1.yes 2.no");
scanf("%d",&a);
}while(a==1);
break;
case 4:do
{
printf("\nEnter your choice:");
scanf("%d",&ch1);
switch(ch1)
{
case 1:delf();
break;
case 2:dele();
break;
case 3:printf("\nEnter the element");
scanf("%d",&m);
dela(m);
break;
}
printf("\nDo you need 2 continue 1.yes 2.no");
scanf("%d",&a);
}while(a==1);
break;
case 5:printf("\nEnter the element");
scanf("%d",&m);
printf("\nEnter key:");
scanf("%d",&k);
modify(k,m);
break;
case 6:exit(0);
}
}while(1);
getch();
}
create_l(int m)
{
nod q,tmp;
tmp=malloc(sizeof(struct node));
tmp->info=m;
if(last->link==last)
{
tmp->link=last;
last->link=tmp;
}
else
{
q=last;
while(q->link!=last)
{
q=q->link;
}
tmp->link=last;
q->link=tmp;
}
disp();
return;
}
inserte(int m)
{
nod q,tmp;
tmp=malloc(sizeof(struct node));
tmp->info=m;
if(last->link==last)
{
tmp->link=last;
last->link=tmp;
}
else
{
q=last;
while(q->link!=last)
{
q=q->link;
}
tmp->link=last;
q->link=tmp;
disp();
}
return;
}
insertf(int m)
{
nod tmp;
tmp=malloc(sizeof(struct node));
tmp->info=m;
tmp->link=last->link;
last->link=tmp;
disp();
return;
}
disp()
{
nod q,c,t;
if(last->link==last)
printf("\nList empty");
q=last->link;
printf("->");
while(q!=last)
{
printf("%d->",q->info);
q=q->link;
}
return;
}
inserta(int key,int data)
{
nod tmp,ptr;
tmp=malloc(sizeof(struct node));
if(tmp==NULL)
printf("\nInsertion not possible!");
else
{
ptr=last;
while(ptr->info!=key && ptr->link!=last)
{
ptr=ptr->link;
}
if(ptr->link==last)
printf("\n%d not found!",key);
else if(ptr->info==key)
{
tmp->link=ptr->link;
tmp->info=data;
ptr->link=tmp;
disp();
}
}
return;
}
display()
{
nod q,c,p,t;
//int t;
if(last->link==last)
printf("\nList empty");
for(q=last->link;q!=last;q=q->link)
{
for(c=q->link;c!=last;c=c->link)
{
if(q->info > c->info)
{
t=q->info;
q->info=c->info;
c->info=t;
}
}
}
q=last->link;
printf("->");
while(q!=last)
{
printf("%d->",q->info);
q=q->link;
}
//printf("%d",q->link);
return;
}
dele()
{
nod ptr,ptr1;
ptr=last;
while(ptr->link!=last)
{
ptr1=ptr;
ptr=ptr->link;
}
ptr1->link=ptr->link;
free(ptr);
disp();
return;
}
delf()
{
nod prev,cur,q;
if(last->link==last)
printf("\nLIst empty");
else
{
prev=last->link;
cur=prev->link;
last->link=cur;
//cur->link=NULL;
free(prev);
disp();
}
return;
}
dela(int m)
{
nod ptr,ptr1;
ptr=last;
ptr1=ptr->link;
while(ptr->link!=last && ptr->info!=m)
{
ptr1=ptr;
ptr=ptr->link;
}
if(ptr->info==m)
{
ptr1->link=ptr->link;
free(ptr);
disp();
}
else
printf("\n%d not found!",m);
return;
}
modify(int key,int data)
{
nod prev,cur;
cur=last;
while(cur->link!=last && cur->info!=key)
{
prev=cur;
cur=cur->link;
}
if(cur->info==key)
cur->info=data;
if(cur->link==last && cur->link!=key)
printf("\n%d not found!",key);
else
disp();
return;
}
//program to implement circular linked list
#include<malloc.h>
#include<conio.h>
#include<stdio.h>
struct node
{
int info;
struct node *link;
}*last;
typedef struct node *nod;
void main()
{
int ch,n,m,i,pos,c,k,a,ch1;
last->link=last;
clrscr();
printf("\nMENU\n1.create\n2.dispaly in sorted order\n3.insert\n 1.front\n 2.end\n 3.any\n4.delete\n 1.front\n 2.end\n 3.any\n5.modify\n6.exit");
do
{
printf("\nEnter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nEnter the number of nodes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter element:");
scanf("%d",&m);
create_l(m);
}
break;
case 2:printf("\nElements in sorted order are.....\n");
display();
break;
case 3:do
{
printf("\nEnter your choice:");
scanf("%d",&c);
switch(c)
{
case 1:printf("\nEnter the element");
scanf("%d",&m);
insertf(m);
break;
case 2:printf("\nEnter the element");
scanf("%d",&m);
inserte(m);
break;
case 3:printf("\nEnter the element");
scanf("%d",&m);
printf("\nEnter key:");
scanf("%d",&k);
inserta(k,m);
break;
default:printf("invalid choice");
}
printf("\nDo you need 2 continue 1.yes 2.no");
scanf("%d",&a);
}while(a==1);
break;
case 4:do
{
printf("\nEnter your choice:");
scanf("%d",&ch1);
switch(ch1)
{
case 1:delf();
break;
case 2:dele();
break;
case 3:printf("\nEnter the element");
scanf("%d",&m);
dela(m);
break;
}
printf("\nDo you need 2 continue 1.yes 2.no");
scanf("%d",&a);
}while(a==1);
break;
case 5:printf("\nEnter the element");
scanf("%d",&m);
printf("\nEnter key:");
scanf("%d",&k);
modify(k,m);
break;
case 6:exit(0);
}
}while(1);
getch();
}
create_l(int m)
{
nod q,tmp;
tmp=malloc(sizeof(struct node));
tmp->info=m;
if(last->link==last)
{
tmp->link=last;
last->link=tmp;
}
else
{
q=last;
while(q->link!=last)
{
q=q->link;
}
tmp->link=last;
q->link=tmp;
}
disp();
return;
}
inserte(int m)
{
nod q,tmp;
tmp=malloc(sizeof(struct node));
tmp->info=m;
if(last->link==last)
{
tmp->link=last;
last->link=tmp;
}
else
{
q=last;
while(q->link!=last)
{
q=q->link;
}
tmp->link=last;
q->link=tmp;
disp();
}
return;
}
insertf(int m)
{
nod tmp;
tmp=malloc(sizeof(struct node));
tmp->info=m;
tmp->link=last->link;
last->link=tmp;
disp();
return;
}
disp()
{
nod q,c,t;
if(last->link==last)
printf("\nList empty");
q=last->link;
printf("->");
while(q!=last)
{
printf("%d->",q->info);
q=q->link;
}
return;
}
inserta(int key,int data)
{
nod tmp,ptr;
tmp=malloc(sizeof(struct node));
if(tmp==NULL)
printf("\nInsertion not possible!");
else
{
ptr=last;
while(ptr->info!=key && ptr->link!=last)
{
ptr=ptr->link;
}
if(ptr->link==last)
printf("\n%d not found!",key);
else if(ptr->info==key)
{
tmp->link=ptr->link;
tmp->info=data;
ptr->link=tmp;
disp();
}
}
return;
}
display()
{
nod q,c,p,t;
//int t;
if(last->link==last)
printf("\nList empty");
for(q=last->link;q!=last;q=q->link)
{
for(c=q->link;c!=last;c=c->link)
{
if(q->info > c->info)
{
t=q->info;
q->info=c->info;
c->info=t;
}
}
}
q=last->link;
printf("->");
while(q!=last)
{
printf("%d->",q->info);
q=q->link;
}
//printf("%d",q->link);
return;
}
dele()
{
nod ptr,ptr1;
ptr=last;
while(ptr->link!=last)
{
ptr1=ptr;
ptr=ptr->link;
}
ptr1->link=ptr->link;
free(ptr);
disp();
return;
}
delf()
{
nod prev,cur,q;
if(last->link==last)
printf("\nLIst empty");
else
{
prev=last->link;
cur=prev->link;
last->link=cur;
//cur->link=NULL;
free(prev);
disp();
}
return;
}
dela(int m)
{
nod ptr,ptr1;
ptr=last;
ptr1=ptr->link;
while(ptr->link!=last && ptr->info!=m)
{
ptr1=ptr;
ptr=ptr->link;
}
if(ptr->info==m)
{
ptr1->link=ptr->link;
free(ptr);
disp();
}
else
printf("\n%d not found!",m);
return;
}
modify(int key,int data)
{
nod prev,cur;
cur=last;
while(cur->link!=last && cur->info!=key)
{
prev=cur;
cur=cur->link;
}
if(cur->info==key)
cur->info=data;
if(cur->link==last && cur->link!=key)
printf("\n%d not found!",key);
else
disp();
return;
}
Thursday, January 19, 2012
c programs: burningminds: c++ program to find saddle point of ...
c programs: burningminds: c++ program to find saddle point of ...: burningminds: c++ program to find saddle point of a matrix : //program to find saddle point of a matrix //fensams@81092 #include #include...
Saturday, January 7, 2012
c++ program to generate reverse pyramid of digits
#include<iostream.h>
#include<conio.h>
class REVERSE
{
private:
int n,i,j,k,s;
public:
void read();
void call();
};
void REVERSE::read()
{
cout<<"enter limit\n";
cin>>n;
}
void REVERSE::call()
{
s=n;
for(i=1;i<=n;i++)
{
for(k=s;k<=n;k++)
{
cout<<" ";
}
k=1;
for(j=1;j<=s;j++)
{
cout<<k++<<" ";
}
cout<<"\n";
s=s-1;
}
}
void main()
{
REVERSE a;
clrscr();
a.read();
a.call();
getch();
}
burningminds: c++ program to find saddle point of a matrix
burningminds: c++ program to find saddle point of a matrix: //program to find saddle point of a matrix //fensams@81092 #include #include class matrix { int A[50][50],row,col...
c++ program to find saddle point of a matrix
//program to find saddle point of a matrix
//fensams@81092
#include<iostream.h>
#include<conio.h>
class matrix
{ int A[50][50],row,col;
public:
void get_matrix();
void saddle();
void put_matrix();
}M;
void matrix::get_matrix()
{ cout<<"ENTER THE ROW AND COLUMN SIZE\n";
cin>>row>>col;
cout<<"ENTER THE ELEMENTS\n";
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
cin>>A[i][j];
}
void matrix::put_matrix()
{ cout<<"THE ENTERED MATRIX IS\n";
for(int i=0;i<row;i++)
{ for(int j=0;j<col;j++)
cout<<A[i][j]<<"\t";
cout<<"\n";
}
}
void matrix::saddle()
{ int big[10],small[10],i,j,max,min;
for(i=0;i<row;i++)
{ small[i]=A[i][0];
for(j=0;j<col;j++)
if(A[i][j]<small[i])
small[i]=A[i][j];
}
for(j=0;j<col;j++)
{ big[j]=A[0][j];
for(i=0;i<row;i++)
if(A[i][j]>big[j])
big[j]=A[i][j];
}
min=big[0];
for(i=0;i<row;i++)
if(big[i]<min)
min=big[i];
max=small[0];
for(j=0;j<col;j++)
if(small[j]>max)
max=small[j];
if(max==min)
cout<<"THE SADDLE POINT : "<<min;
else
cout<<"NO SADDLE POINT\n";
}
void main()
{ clrscr();
M.get_matrix();
M.put_matrix();
M.saddle();
getch();
}
Subscribe to:
Posts (Atom)