1. Perform Linear Search and Binary Search on an array.
Descriptions of the programs:
Read and array of type integer.
Input element from user for searching.
Search the element by passing the array to a function and then returning the position of the element from the function else return -1 if the element is not found.
Display the positions where the element has been found.
2. Implement sparse matrix using array.
Description of program:
Read a 2D array from the user.
Store it in the sparse matrix form, use array of structures.
Print the final array.
3. Create a linked list with nodes having information about a student and perform.
Description of the program:
Insert a new node at specified position.
Delete of a node with the roll number of student specified.
Reversal of that linked list.
4. Create doubly linked list with nodes having information about an employee and perform Insertion at front of doubly linked list and perform deletion at end of that doubly linked list.
5. Create circular linked list having information about a college and perform Insertion at front perform Deletion at end.
6. Create a stack and perform Pop, Push, Traverse operations on the stack using Linear Linked list.
7. Create a Linear Queue using Linked List and implement different operations such as Insert, Delete, and Display the queue elements.
General Principles of Intellectual Property: Concepts of Intellectual Proper...
Data Structure Project File
1. INDEX
S. No. Title Page No. Teacher’s Signature
1. Perform Linear Search and Binary Search on an
array.
Descriptions of the programs:
a. Read and array of type integer.
b. Input element from user for searching.
c. Search the element by passing the array
to a function and then returning the
position of the element from the function
else return -1 if the element is not found.
d. Display the positions where the element
has been found.
01 - 04
2. Implement sparse matrix using array.
Description of program:
a. Read a 2D array from the user.
b. Store it in the sparse matrix form, use
array of structures.
c. Print the final array.
05 - 06
3. Create a linked list with nodes having
information about a student and perform.
Description of the program:
a. Insert a new node at specified position.
b. Delete of a node with the roll number of
student specified.
c. Reversal of that linked list.
07 - 13
4. Create doubly linked list with nodes having
information about an employee and perform
Insertion at front of doubly linked list and
perform deletion at end of that doubly linked list.
14 - 17
2. 5. Create circular linked list having information
about a college and perform Insertion at front
perform Deletion at end.
18 - 22
6. Create a stack and perform Pop, Push, Traverse
operations on the stack using Linear Linked list.
23 - 26
7. Create a Linear Queue using Linked List and
implement different operations such as Insert,
Delete, and Display the queue elements.
27 - 30
3. 01.
PerformLinear Search and Binary Search on an array.
Description of programs:
a. Read an array of type integer.
b. Inputelement from user for searching.
c. Search the element by passing the array to a function and then returning the
position of the element fromthe function else return -1 if the element is not
found.
d. Display the position wherethe element has been found.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void LinearSearch( );
void BinarySearch( );
int i,j,n,a[20],count=0,yn=-1,choice,mid,first,last;
void main( )
{
printf("ntNAME- Devesh Kumarnt");
printf("ntNorthern India Engineering Collegent");
printf("nt");
while(choice!=3)
{
printf("nntPress 1 For Linear Search");
printf("nntPress 2 For Binary Search");
printf("nntPress 3 For Exit");
printf("nntPleaseEnter your choice :");
Experiment No - 1
4. scanf("%d",&choice);
switch(choice)
{
case1: LinearSearch();
break;
case2: BinarySearch();
break;
case 3: Exit(1);
default: printf("nntYou Have Entered Wrong Choice");
printf("tEnter 1 for Continue :");
scanf("%d",&choice);
}
}
getch();
}
void LinearSearch()
{
printf("nntLinear Search :");
printf("nntEnter The Size Of The Array : ");
scanf("%d",&n);
printf("nntEnter The Sorted Array");
printf("nntEnter The %d Elements : n",n);
printf("nt");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
printf("nt");
}
printf("nntEnter The Elements To Be Searched :");
scanf("%d",&j);
printf("nntOriginalArraynnt");
for(i=0;i<n;i++)
{
5. printf("%dt",a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]==j)
{
printf("nntElement %d Is Found At Location %dn",j,i+1);
break;
}
else
{
count++;
}
}
if(count==n)
{
n=-1;
printf("nntElement %d is not in this array",n);
}
}
void BinarySearch()
{
printf("nntBinary Search : ");
printf("nntEnter The Size Of The Array :");
scanf("%d",&n);
printf("nntEnter The Sorted Array");
printf("nntEnter The %d Elements :nt",n);
printf("nt");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
printf("nt");
}
printf("nntEnter The Elements To Be Searched :");
scanf("%d",&j);
printf("nntOriginalarray nnt");
7. 05.
Implement sparsematrixusing array.
Description of program:
a. Read a 2D array fromthe user.
b. Store it in the sparsematrixform, use array of structures.
c. Printthe final array.
Source Code:
#include<stdio.h>
#include<conio.h>
main( )
{
int A[10][10],B[10][3],m,n,s=0,i,j;
printf("ntNAME - Devesh Kumarnt");
printf("ntNorthern India Engineering Collegent");
printf("nt");
printf("ntEnter the order MxN of the matrixnt");
printf("ntEnter the value of M :");
scanf("%d",&m);
printf("ntEnter the value of N :");
scanf("%d",&n);
printf("ntEnter the elements in the matrixnnt");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("nt%d Row and %d Column - t",i,j);
scanf("%d",&A[i][j]);
}
}
Experiment No - 2
9. 07.
3. Create a linked list with nodes having information about a student and perform
Description of program:
a. Inserta new node at specified position.
b. Delete of a node with the roll number of student specified.
c. Reversal of that linked list.
Source Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
structstudent
{
char name[100];
int roll;
struct student*next;
};
structstudent *first=NULL,*last=NULL,*k;
void create(int n)
{
int i;
first=(structstudent*)malloc(sizeof(structstudent));
printf("ntEnter The Name Of The Student:");
scanf("%s",first->name);
printf("ntEnter The Roll Number Of The Student:");
scanf("%d",&first->roll);
first->next=NULL;
last=first;
Experiment No - 3
10. for(i=1;i<n;i++)
{
k=(structstudent*)malloc(sizeof(structstudent));
printf("ntEnter The Name Of The Student:");
scanf("%s",k->name);
printf("ntEnter The Roll Number Of The Student:");
scanf("%d",&k->roll);
k->next=NULL;
last->next=k;
last=k;
}
}
void display( )
{
structstudent *t;
int count=0;
t=first;
printf("ntTheDetails Of The Students Arenn");
printf("tS.No.tRollNo.tNamen");
while(t!=NULL)
{
count++;
printf("nt%dt%dtt%s",count,t->roll,t->name);
t=t->next;
}
}
void insertafter()
{
int r;
int flag=0;
structstudent *t;
printf("ntEnter The Roll Number You Want To InsertAfter That:");
scanf("%d",&r);
12. printf("ntEnter The Roll Number You Want To Delete:");
scanf("%d",&r);
if(first->roll==r)
{
first=first->next;
flag=1;
}
else
{
back=first;
k=first->next;
while(k!=NULL && flag==0)
{
if(k->roll==r)
{
back->next=k->next;
flag=1;
printf("ntThe Record Deleted : ");
getch();
}
}
}
if(flag==0)
printf("ntThe Element Not Found!!!");
}
else
{
printf("ntNo Record In The Database");
getch();
}
}
void search()
{
int r;
int flag=0;
13. structstudent *t;
if(first!=NULL)
{
printf("ntEnter The Roll Number You Want To Search:");
scanf("%d",&r);
t=first;
while(t!=NULL)
{
if(t->roll==r)
{
printf("nntThe Roll Number Found In The List!!!n”);
printf(ntHis Name Is %sn",t->name);
flag=1;
break;
}
t=t->next;
}
if(flag==0)
printf("ntTheRoll Number Not In Database!!");
}
else
{
printf("ntNo Element In The List ");
getch();
}
}
void reverse_list()
{
structstudent *temp,*temp1,*var;
temp=first;
var=NULL;
while(temp!=NULL)
{
temp1=var;
var=temp;
temp=temp->next;
var->next=temp1;
14. }
first=var;
}
int main()
{
int n,o;
printf("ntNAME- Devesh Kumarnt");
printf("ntNorthern India Engineering Collegent");
printf("nt");
while(o!=0)
{
printf("nntPleasePress Enter To Continue : nnt");
getch();
printf("ntEnter 1 For Creating Database");
printf("ntEnter 2 For Displaying Database");
printf("ntEnter 3 For Inserting An Record After Another");
printf("ntEnter 4 For Deleting A Record");
printf("ntEnter 5 For Searching A Record");
printf("ntEnter 6 Reversing The Nodes");
printf("ntEnter 0 For Exit!");
printf("ntPleaseEnter Your Choice:");
scanf("%d",&o);
switch(o)
{
case1: printf("ntEnter The Maximum Size Of The Data Base:");
scanf("%d",&n);
create(n);
break;
case2: display( );
break;
case3: insertafter( );
break;
15. case 4: del(); 13.
break;
case 5: search();
break;
case 6: reverse_list();
display();
break;
case 0: exit(0);
break;
default: printf("ntYou Have Entered A Wrong Choice!!!");
}
}
getch();
}
16. 14.
Create doubly linked list with nodes having information about an employee and
performInsertion atfront of doubly linked list and performdeletion at end of that
doubly linked list.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
structemployee
{
int num;
long int salary;
char name[20];
structemployee *prev;
structemployee *next;
}
*start,*rear,*k;
typedef structemployee employee;
employee *create();
void addemployee(employee *);
void display(employee*);
void addbeg(employee*);
void del( );
void main( )
{
int m,o;
Experiment No - 4
17. employee *p;
start=NULL;
rear=NULL;
printf("ntNAME- Devesh Kumarnt");
printf("ntNorthern India Engineering Collegent");
printf("nt");
printf("Deletion At End");
printf("ntnt");
printf("ntEnter the Number of Employees :");
scanf("%d",&m);
while(m--)
{
p=create();
addbeg(p);
}
while(o!=0)
{
printf("nntPleasePress Enter to Continue nt");
getch();
printf("ntEnter 1 To InsertNew Recordnt");
printf("ntEnter 2.To Delete Record FromEndnt");
printf("ntEnter 3.To Display All Records nt");
printf("ntEnter 0.To Exitnt");
printf("ntEnter Your Choice :");
scanf("%d",&o);
switch(o)
{
case 1: p=create();
addbeg(p);
break;
case 2: del();
break;
18. case 3: display(start);
break;
}
}
}
employee *create()
{
employee *k;
k=((employee*)malloc(sizeof(employee)));
printf("ntEnter The Employee Number : ");
scanf("%d",&k->num);
printf("ntEnter The Name of The Employee : ");
scanf("%s",k->name);
printf("ntEnter The Salary Of The Employee : ");
scanf("%ld",&k->salary);
k->next=NULL;
k->prev=NULL;
return k;
}
void display(employee*k)
{
int count=0;
printf("ntS.No.tEmployeeNumberttNamettSalaryn");
while(k!=NULL)
{
count++;
printf("nt%dt%dttt%stt%ld",count,k->num,k->name,k->salary);
k=k->next;
}
}
void addbeg(employee*k)
{
if(start==NULL)
20. 18.
Create circular linked list having information about an college and perform
Insertion atfront performDeletion at end.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
structnode
{
int id;
char name[20];
char director[20];
char add[20];
char contact[11];
structnode *next;
}
*start,*rear,*k;
typedef structnode node;
node *create();
void display();
void addbeg(node*);
node *del(node *);
main()
{
int m,o;
node *p;
start=NULL;
Experiment No - 5
21. printf("ntNAME- Devesh Kumarn");
printf("ntNorthern India Engineering Collegen");
printf("nt");
printf("To PerformDeletion At End");
printf("nnt");
printf("ntPleasePress Enter To Continue :");
getch();
printf("nt");
printf("ntEnter Initial Number Of Colleges :");
scanf("%d",&m);
while(m--)
{
p=create();
addbeg(p);
}
while(o!=0)
{
printf("nntPleasePress Enter To Continue");
getch();
printf("nntPress 1 To Insertnew Record At Front");
printf("nntPress 2.To Delete Record From End");
printf("nntPress 3.To Display AllRecords");
printf("nntPress 0.To Exit");
printf("nntPress Your Choice: ");
scanf("%d",&o);
switch(o)
{
case 1: p=create();
addbeg(p);
break;
case 2: start=del(start);
break;
case 3: display( );
break;
22. }
}
}
node *create()
{
node *k;
k=(node *)malloc(sizeof(node));
printf("ntEnter The ID : ");
scanf("%d",&k->id);
printf("ntEnter Name Of College : ");
scanf("%s",k->name);
printf("ntEnter Name Of Director : ");
scanf("%s",k->director);
printf("ntEnter Address Of TheCollege : ");
scanf("%s",k->add);
printf("ntEnter Contact Number : ");
scanf("%s",k->contact);
k->next=NULL;
return k;
}
void display()
{
node *k;
int count=0;
k=start;
printf("nntS.No.tIDtNametDirectortAddressttContactn");
do
{
count++;
printf("nt%dt%dt%st%st%stt%sn",count,k->id,
k>name,k>director,k>add,k->contact);
k=k->next;