0% found this document useful (0 votes)
104 views16 pages

14 Sample Format For Experiment

The document contains details of 8 experiments conducted by a student on various data structures topics like dynamic memory allocation, structures, stacks, queues, linked lists, doubly linked lists, and stack implementation using linked lists. Each experiment contains the aim, source code of the program written, and output for that program. The programs demonstrate basic operations and traversal techniques for the data structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views16 pages

14 Sample Format For Experiment

The document contains details of 8 experiments conducted by a student on various data structures topics like dynamic memory allocation, structures, stacks, queues, linked lists, doubly linked lists, and stack implementation using linked lists. Each experiment contains the aim, source code of the program written, and output for that program. The programs demonstrate basic operations and traversal techniques for the data structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Experiment No.

DYNAMIC MEMORY ALLOCATION


Name of Student: Aditya Jajpure

Class: CS III sem

Enrollment No: 0827CS151014

Batch: B-01

Date of Experiment: 02/09/2016

Date of Submission:

Remarks by faculty:

Grade:

Signature of student:

Signature of Faculty:

AIM: WRITE

Submitted on:

(Vandana Kate)

A PROGRAM FOR DYNAMIC MEMORY ALLOCATION

PROGRAM SOURCE CODE://PROGRAM-1


//WRITE A PROGRAM FOR DYNAMIC MEMORY ALLOCATION

#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

PROGRAM WITH THE HELP OF STRUCTURE


Name of Student: Aditya Jajpure

Class: CS III sem

Enrollment No: 0827CS151014

Batch: B-01

Date of Experiment: 02/09/2016

Date of Submission:

Remarks by faculty:

Grade:

Signature of student:

Signature of Faculty:

AIM: WRITE

Submitted on:

(Vandana Kate)

A PROGRAM WITH THE HELP OF A STRUCTURE

PROGRAM SOURCE CODE://PROGRAM-2


//WRITE A PROGRAM WITH THE HELP OF STRUCTURE

#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

STACK IMPLEMENTATION WITH THE HELP OF ARRAY


Name of Student: Aditya Jajpure

Class: CS III sem

Enrollment No: 0827CS151014

Batch: B-01

Date of Experiment: 02/09/2016

Date of Submission:

Remarks by faculty:

Grade:

Signature of student:

Signature of Faculty:

AIM: WRITE

Submitted on:

(Vandana Kate)

A PROGRAM FOR STACK IMPLEMENTATION WITH ARRAY

PROGRAM SOURCE CODE://PROGRAM-3


//WRITE A PROGRAM FOR STACK IMPLEMENTATION WITH THE HELP OF ARRAY

#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

IMPLEMENTATION OF QUEUE USING TWO STACKS


Name of Student: Aditya Jajpure

Class: CS III sem

Enrollment No: 0827CS151014

Batch: B-01

Date of Experiment: 16/09/2016

Date of Submission:

Remarks by faculty:

Grade:

Signature of student:

Signature of Faculty:

AIM: WRITE

Submitted on:

(Vandana Kate)

A PROGRAM FOR QUEUE IMPLEMENTATION USING TWO STACKS

PROGRAM SOURCE CODE://PROGRAM-4


//WRITE A PROGRAM FOR QUEUE IMPLEMENTATION USING TWO STACKS

#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

CREATION OF LINKED LIST AND ITS TRAVERSAL


Name of Student: Aditya Jajpure

Class: CS III sem

Enrollment No: 0827CS151014

Batch: B-01

Date of Experiment: 16/09/2016

Date of Submission:

Remarks by faculty:

Grade:

Signature of student:

Signature of Faculty:

Submitted on:

(Vandana Kate)

AIM: WRITE

A PROGRAM FOR CREATION OF LINKED LIST AND ITS


TRAVERSAL
PROGRAM SOURCE CODE://PROGRAM-5
//WRITE A PROGRAM FOR CREATION OF LINKED LIST AND ITS TRAVERSAL

#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

CREATION OF LINKED LIST AND ITS REVERSE TRAVERSAL


Name of Student: Aditya Jajpure

Class: CS III sem

Enrollment No: 0827CS151014

Batch: B-01

Date of Experiment: 16/09/2016

Date of Submission:

Remarks by faculty:

Grade:

Signature of student:

Signature of Faculty:

Submitted on:

(Vandana Kate)

AIM: WRITE

A PROGRAM FOR CREATION OF LINKED LIST AND ITS REVERSE


TRAVERSAL
PROGRAM SOURCE CODE://PROGRAM-1
//WRITE A PROGRAM FOR CREATION OF LINKED LIST AND ITS REVERSE TRAVERSAL

#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

DOUBLY LINKED LIST


Name of Student: Aditya Jajpure

Class: CS III sem

Enrollment No: 0827CS151014

Batch: B-01

Date of Experiment: 23/09/2016

Date of Submission:

Remarks by faculty:

Grade:

Signature of student:

Signature of Faculty:

Submitted on:

(Vandana Kate)

AIM: WRITE

A PROGRAM FOR CREATION AND TRAVERSAL OF DOUBLY


LINKED LIST
PROGRAM SOURCE CODE://PROGRAM-7
//WRITE A PROGRAM FOR CREATION AND TRAVERSAL OF DOUBLY LINKED LIST

#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

STACK IMPLEMENTATION USING LINKED LIST


Name of Student: Aditya Jajpure

Class: CS III sem

Enrollment No: 0827CS151014

Batch: B-01

Date of Experiment: 23/09/2016

Date of Submission:

Remarks by faculty:

Grade:

Signature of student:

Signature of Faculty:

AIM: WRITE

(Vandana Kate)

A PROGRAM FOR STACK IMPLEMENTATION USING LINKED LIST

PROGRAM SOURCE CODE:-

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

You might also like