An Overview

All the necessary study material for b-tech students.

What we have to offer you.

Codes,Syllabus,Study material,Lab manuals,Assignments and many more . . .

Surfing becomes easy.

You can have any material from our website and post your valuable comments for further improvement.

Get the latest techno news

Get yourself updated with this fast changing dynamic world and all the changes in b-tech pattern.

All the best resources for you.

We have done our level best to provide you with the best of the degree and thus this site is devoted to b-tech exclusively.

Showing posts with label DSA. Show all posts
Showing posts with label DSA. Show all posts

15 November 2011

Insert the node in the begining of the list.

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
 int info;
 struct node* link;
} ;
struct node* obj;
void main()
{  void create();
void insertbeg();
void traverse();
clrscr();
create();
insertbeg();
traverse();
getch();
 }
void create()
{
 struct node*ptr,*nxt;
 char ch;
 ptr=(struct node*)malloc(sizeof(struct node));
 printf("Insert node");
 scanf("%d",&ptr->info);
 obj=ptr;
 do{
 nxt=(struct node*)malloc(sizeof(struct node));
 printf("Insert node");
 scanf("%d",&nxt->info);
 ptr->link=nxt;
 ptr=nxt;
 printf("Enter Y/N to insert more elements");
 ch=getche();
 }
 while(ch=='Y');
 ptr->link=0;
}
void insertbeg()
{       struct node*nxt;
 char c;
       // ptr=(struct node*)malloc(sizeof(struct node));
 nxt=(struct node*)malloc(sizeof(struct node));
 do{
 printf( "Do u want to insert node in the begning of the list");
 c=getche();
 }
 while(c=='Y');
 printf("insert node");
 scanf("%d",&nxt->info);
 nxt->link=obj;
       obj=nxt;
 }
void traverse()
{     struct node*ptrr;
       ptrr=obj;
      do
      {
      printf("%d",ptrr->info);
      ptrr=ptrr->link;
      } while(ptrr!=0);
  }

A DSA program of stacking.


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *next;
};
struct stack
{
struct stack *top,*next;
};
void main()
{
char ch='y';
struct node *node1;
struct stack *stack1;
stack1->top=NULL;
while(ch=='y')
{
node1=malloc(sizeof (struct node));
if(stack1->top==NULL)
{
node1->next=NULL;
}
else
{
node1->next=NULL;
}
      // stack1=node1;
printf("\n Enter any value");
scanf("%d",& node1->info);
printf("\n Enter your choice (y/n):");
fflush(stdin);
scanf("%c", &ch);
}
for(  ;stack1->top!=NULL;stack1->top=stack1->top->next)
{
printf("%d",node1->info);
}
getch();
}

a program in DSA as employee que


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct employee
{
int emp_id;
char emp_name[15];
int bs;
float gs;
struct employee *next;
};
struct queue
{
struct employee *rear;
struct employee *front;
};
void main()
{
int bs;
float ta,da,hra,gs;
struct employee *emp1;
struct queue *queue1;
char ch='y';
clrscr();
queue1=NULL;
while(ch=='y')
{
emp1= malloc(sizeof (struct employee));
if (queue1==NULL)
{
queue1->front=queue1->rear=emp1;
}
else
{
queue1->front=emp1;
queue1->front=queue1->front->next;
}
queue1->front->next=NULL;
printf("\n Enter employee id : ");
scanf("%d",& emp1->emp_id);
printf("\n Enter employee name :");
scanf("%s",& emp1->emp_name);
printf("\n Enter basic salary :");
scanf("%d",& emp1->bs);
ta=0.20*bs;
da=0.40*bs;
hra=0.15*bs;
gs=bs+ta+da+hra;
printf("\n\t Gross salary of employee is : %f",gs);
printf("\n\n\t Enter your choice(y/n) :");
fflush(stdin);
scanf("%c",& ch);
}
for(  ;queue1->front!=NULL;queue1->front=queue1->front->next)
{
printf("\n emp_id = %d",emp1->emp_id);
printf("\n emp_name = %s",emp1->emp_name);
printf("\n basic salary = %d",emp1->bs);
printf("\n gross salary = %f\n",gs);
}
if(gs>15000)
{
printf("\n\tGross salary is more than 15000");
}
else
{
printf("\n\tGross salary is less than 15000");
}
getch();
}

A DSA program showing que.


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node*next;
};
struct queue
{
struct node*rear;
struct node *front;
};
void main()
{
struct node *node1;
struct queue *queue1;
char ch='y';
queue1=NULL;
while(ch=='y')
{
node1=malloc(sizeof(struct node));
if(queue1==NULL)
{
queue1->front=queue1->rear=node1;
}
else
{
queue1->front=node1;
queue1->front=queue1->front->next;
}
queue1->front->next=NULL;
printf("\n enter any value ") ;
scanf("%d",&node1->info) ;
printf("\n do you want to more press your choice(Y/N) :") ;
fflush(stdin);
scanf("%c",&ch);
}
for( ;queue1->front!=NULL;queue1->front=queue1->front->next)
{
printf("%d",queue1->front->info);
}
getch();
}

14 November 2011

A program in class array (C++)

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class array
{
private:
int arr1[5];
public:
void getdata();
void putdata();

};
void array::getdata()
{
for(int i=0;i<=4;i++)
{
cout<<"\n Enter the number :";
cin>>arr1[i];
}
}
void array::putdata()
{
for(int i=0;i<=4;i++)
{
cout<<"\n"<<arr1[i];
}
}
void main()
{
array a;
clrscr();
a.getdata();
a.putdata();
getch();
}