Beruflich Dokumente
Kultur Dokumente
Batch: B-01
Date of Submission:
Remarks by faculty:
Grade:
Signature of student:
Signature of Faculty:
AIM: WRITE
Submitted on:
(Vandana Kate)
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
void main()
{
clrscr();
int n,*a;
cout<<"Enter the no. of elements to be entered:";
cin>>n;
a=(int*)(malloc(n*sizeof(int)));
for(int i=0;i<=n-1;i++)
{
cout<<"Enter element "<<i+1<<":";
cin>>*(a+i);
}
cout<<"The inserted elements are: ";
for(i=0;i<=n-1;i++)
{
cout<<*(a+i)<<"\t";
}
getch();
}
OUTPUT:
Experiment No. 2
Batch: B-01
Date of Submission:
Remarks by faculty:
Grade:
Signature of student:
Signature of Faculty:
AIM: WRITE
Submitted on:
(Vandana Kate)
#include<iostream.h>
#include<conio.h>
struct rect
{
int l,b;
int area;
};
void main()
{
clrscr();
rect r[4];
for(int i=0;i<=3;i++)
{
cout<<"\n\n***RECTANGLE "<<i+1<<"***\n\n";
cout<<"Enter length:";
cin>>r[i].l;
cout<<"Enter breadth:";
cin>>r[i].b;
r[i].area=r[i].l*r[i].b;
cout<<"Calculated area:"<<r[i].area;
}
getch();
2
}
OUTPUT:
Experiment No. 3
Batch: B-01
Date of Submission:
Remarks by faculty:
Grade:
Signature of student:
Signature of Faculty:
AIM: WRITE
Submitted on:
(Vandana Kate)
#include<iostream.h>
#include<conio.h>
struct stack
{
int a[5];
int top;
};
void push(stack *s);
void pop(stack *s);
void main()
{
clrscr();
stack s1;
s1.top=-1;
cout<<"\nEnter elements to be inserted in stack:";
for(int i=0;i<=4;i++)
push(&s1);
pop(&s1);
getch();
}
void push(stack *s)
{
if(s->top==4)
cout<<"Overflow";
else
{
s->top++;
cin>>s->a[s->top];
4
}
}
void pop(stack *s)
{
if(s->top==-1)
cout<<"Underflow";
else
{
cout<<"Element deleted from stack:"<<s->a[s->top];
s->top--;
}
}
OUTPUT:
Experiment No. 4
Batch: B-01
Date of Submission:
Remarks by faculty:
Grade:
Signature of student:
Signature of Faculty:
AIM: WRITE
Submitted on:
(Vandana Kate)
#include<iostream.h>
#include<conio.h>
struct stack
{
int a[5];
int top;
};
void push(stack *s1);
void pop(stack *s1);
void main()
{
clrscr();
stack s1;
s1.top=-1;
for(int i=0;i<=4;i++)
push(&s1);
pop(&s1);
getch();
}
void push(stack *s1)
{
stack *s2;
s2->top=-1;
6
if(s1->top==5)
cout<<"Overflow";
else
{
if(s1->top==-1)
{s1->top++;
cin>>s1->a[s1->top];}
else
{
while(s1->top!=-1)
{
s2->top++;
s2->a[s2->top]=s1->a[s1->top];
s1->top--;
}
s1->top++;
cin>>s1->a[s1->top];
while(s2->top!=-1)
{
s1->top++;
s1->a[s1->top]=s2->a[s2->top];
s2->top--;
}
}
}
}
void pop(stack *s1)
{
if(s1->top==-1)
cout<<"Underflow";
else
{
cout<<"Element deleted:"<<s1->a[s1->top];
s1->top--;
}
}
OUTPUT:
Experiment No. 5
Batch: B-01
Date of Submission:
Remarks by faculty:
Grade:
Signature of student:
Signature of Faculty:
Submitted on:
(Vandana Kate)
AIM: WRITE
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
struct LL
{
int data;
struct LL *next;
};
void main()
{
clrscr();
struct LL *node,*start,*node1,*temp;
node=(struct LL*)malloc(sizeof(struct LL));
cout<<"Enter element:";
cin>>node->data;
8
node->next=NULL;
start=node;
for(int i=1;i<=4;i++)
{
node1=(struct LL*)malloc(sizeof(struct LL));
cout<<"Enter element:";
cin>>node1->data;
node1->next=NULL;
node->next=node1;
node=node1;
}
cout<<"\nThe entered elements are:";
temp=start;
while(temp->next!=NULL)
{
cout<<start->data<<" ";
temp=start;
start=start->next;
};
getch();
}
OUTPUT:
Experiment No. 6
Batch: B-01
Date of Submission:
Remarks by faculty:
Grade:
Signature of student:
Signature of Faculty:
Submitted on:
(Vandana Kate)
AIM: WRITE
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
struct LL
{
int data;
struct LL *next;
};
void main()
{
10
clrscr();
struct LL *node,*start,*node1,*temp;
node=(struct LL*)malloc(sizeof(struct LL));
cout<<"Enter element:";
cin>>node->data;
node->next=NULL;
start=node;
for(int i=1;i<=4;i++)
{
node1=(struct LL*)malloc(sizeof(struct LL));
cout<<"Enter element:";
cin>>node1->data;
node1->next=node;
node=node1;
}
temp=node1;
cout<<"\nThe elements of linked list are:";
while(temp->next!=NULL)
{
cout<<node1->data<<" ";
temp=node1;
node1=node1->next;
}
getch();
}
OUTPUT:
11
Experiment No. 7
Batch: B-01
Date of Submission:
Remarks by faculty:
Grade:
Signature of student:
Signature of Faculty:
Submitted on:
(Vandana Kate)
AIM: WRITE
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
struct LL
12
{
int data;
struct LL *next;
struct LL *pre;
};
void main()
{
clrscr();
struct LL *node,*start,*node1,*temp;
node=(struct LL*)malloc(sizeof(struct LL));
cout<<"Enter element:";
cin>>node->data;
node->next=NULL;
node->pre=NULL ;
start=node;
for(int i=1;i<=4;i++)
{
node1=(struct LL*)malloc(sizeof(struct LL));
cout<<"Enter element:";
cin>>node1->data;
node1->next=NULL;
node1->pre=node;
node->next=node1;
node=node1;
node=node1;
}
cout<<"\nSimple traversal:";
temp=start;
while(temp->next!=NULL)
{
cout<<start->data<<" ";
temp=start;
start=start->next;
}
temp=node1;
cout<<"\nReverse traversal:";
while(temp->pre!=NULL)
{
cout<<node1->data<<" ";
temp=node1;
node1=node1->pre;
}
getch();
}
OUTPUT:
13
Experiment No. 8
Batch: B-01
Date of Submission:
Remarks by faculty:
Grade:
Signature of student:
Signature of Faculty:
AIM: WRITE
(Vandana Kate)
14
Submitted on:
//PROGRAM-8
//WRITE A PROGRAM FOR STACK IMPLEMENTATION USING LINKED LIST
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
struct stack
{
int data;
struct stack *next;
};
void push(int k);
void pop();
struct stack *top=NULL;
void main()
{
clrscr();
int n;
for(int i=1;i<=5;i++)
{
cout<<"Enter element to insert:";
cin>>n;
push(n);
}
pop();
pop();
getch();
}
void push(int k)
{
struct stack *node;
node=(struct stack*)malloc(sizeof(struct stack));
node->data=k;
node->next=top;
top=node;
}
void pop()
{
if(top==NULL)
cout<<"Underflow";
else{
cout<<"\nElement deleted:"<<top->data;
top=top->next; }
}
OUTPUT:
15
16