SlideShare une entreprise Scribd logo
1  sur  32
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
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
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
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++)
{
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");
for(i=0;i<n;i++) 04.
{
printf("%dt",a[i]);
}
first=0;
last= n-1;
while(first<=last)
{
mid=(first+last)/2;
if(j<a[mid])
{
last=mid-1;
}
else if(j>a[mid])
{
first=mid+1;
}
else if(j==a[mid])
{
printf("nntElement %d Is Found AtLocation %dn",j,mid+1);
yn=0;
break;
}
}
if(yn==1)
{
j=-1;
printf("nntElement %d Is NotIn This Array",j);
}
}
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
printf("ntThe given matrix is:nnt"); 06.
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",A[i][j]);
printf("t");
}
printf("nnt");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(A[i][j]!=0)
{
B[s][0]=A[i][j];
B[s][1]=i;
B[s][2]=j;
s++;
}
}
}
printf("ntThesparsematrix is given by:nn");
printf("tValuetRowtColumnnnt");
for(i=0;i<s;i++)
{
for(j=0;j<3;j++)
{
printf("%d",B[i][j]);
printf("t");
}
printf("nnt");
}
getch();
}
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
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);
printf("nt");
if(first!=NULL)
{
t=first;
while(t!=NULL)
{
if(t->roll==r)
{
k=(structstudent*)malloc(sizeof(structstudent));
printf("ntRoll NotttNamen");
printf("nt%dttt%s",t->roll,t->name);
printf("nntEnter The Name Of The Student : ");
scanf("%s",k->name) ;
printf("ntEnter The Roll No Of The Student : ");
scanf("%d",&k->roll);
k->next=t->next;
t->next=k;
flag=1;
break;
}
t=t->next;
}
if(flag==0)
printf("ntThe Element Not Found!!!");
}
else
printf("tElement Not Found ");
}
void del()
{
struct student*back,*t,*k;
int r;
int flag=0;
if(first!=NULL)
{
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;
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;
}
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;
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();
}
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
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;
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)
{ 17.
start=k;
rear=k;
}
else
{
k->next=start;
start->prev=k;
start=k;
}
}
void del()
{
employee *temp;
if(start==NULL)
return;
else if (rear->prev==NULL)
{
temp=rear;
start=rear=NULL;
}
else
{
temp=rear;
rear=rear->prev;
rear->next=NULL;
free(temp);
printf("ntNodeDeletednt");
}
}
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
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;
}
}
}
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;
}
while(k!=start);
}
void addbeg(node*k)
{
node *n=start;
if(start==NULL)
{
start=k;
start->next=start;
}
else
{
while(n->next!=start)
n=n->next;
k->next=start;
start=k;
n->next=start;
}
}
node *del(node *start)
{
node *p,*q;
p=start;
if(p==NULL)
{
printf("ntListIs Emptyn");
}
else
{
while(p->next!=rear)
{
q=p;
p=p->next;
}
printf("ntRecord Deleted"); 22.
q->next=p->next;
}
rear=q;
return start;
}
23.
Create a stack and performPop, Push, Traverseoperations on the stack using
Linear Linked list.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
structstack
{
int info;
struct stack *next;
}
*top,*rear,*k;
typedef structstack stack;
stack *create(int);
void push(stack *);
void display(stack *);
void peep(int);
void pop();
void main()
{
int m=8,a,choice1;
stack *p;
top=NULL;
printf("ntNAME- Devesh Kumarnt");
printf("ntNorthern India Engineering Collegent");
printf("nt");
printf("ntPleasePress Enter To Continuent");
Experiment No - 6
getch();
printf("ntEnter Eight Numbersn");
while(m--)
{
printf("nt");
scanf("%d",&a);
p=create(a);
push(p);
}
printf("nt");
dispaly(top);
printf("nt");
do
{
printf("ntEnter 1 To PUSHnt");
printf("ntEnter 2 To POPnt");
printf("ntEnter 3 To SEARCHnt");
printf("ntEnter Your Choice :");
scanf("%d",&m);
switch(m)
{
case 1: printf("ntEnter A Value -");
scanf("%d",&m);
printf("n");
p=create(m);
push(p);
break;
case 2: printf("n");
pop();
break;
case 3: printf("ntEnter Value To Search -");
scanf("%d",&a);
printf("nn");
peep(a);
break;
default: printf("ntYou HaveEntered Wrong Choicen");
}
printf("t");
dispaly(top);
printf("nt");
printf("ntEnter 1 To Continue :");
scanf("%d",&choice1);
}
while(choice1==1);
getch();
}
stack *create(int m)
{
stack *k;
k=((stack *)malloc(sizeof(stack)));
k->info=m;
k->next=NULL;
return k;
}
void push(stack *n)
{
if(top==NULL)
{
top=n;
}
else
{
n->next=top;
top=n;
}
}
dispaly(stack *k) 26.
{
while(k!=NULL)
{
printf("%d->",k->info);
k=k->next;
}
}
void peep(int val)
{
stack *p=top;
stack *k;
int found =1;
while(p!=NULL)
{
if(p->info==val)
{
printf("tValueFoundnn");
found=0;
break;
}
p=p->next;
}
if(found)
printf("ntValueNot Found");
}
void pop( )
{
stack *k=top;
top=top->next;
free(k);
}
27.
Create a Linear Queue using Linked Listand implement different operations such
as Insert, Delete, and Display the queue elements.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
structqueue
{
int info;
structqueue *next;
}
*front,*rear,*k;
typedef structqueue queue;
queue *create(int);
void addq(queue*);
void delq();
void display(queue*);
void search(int);
void main()
{
int m=8,a,choice;
queue *p;
front=rear=NULL;
printf("ntNAME - Devesh Kumarn");
printf("ntNorthern India Engineering Collegen");
printf("ntPress a key : nt");
Experiment No - 7
getch();
printf("n");
printf("ntEnter Eight Numbersn");
printf("nn");
while(m--)
{
printf("t");
scanf("%d",&a);
p=create(a);
addq(p);
}
printf("t");
printf("nnt");
display(front);
printf("nntMENUn");
printf("nntEnter your choicen");
printf("ntTo Add Node, Enter 1 nnt");
printf("ntTo Delete Node, Enter 2nnt");
printf("ntTo Search Value, Enter 3nnt");
scanf("%d",&m);
switch(m)
{
case 1: printf("nntEnter a Value = n");
scanf("%d",&m);
p=create(m);
addq(p);
break;
case 2: delq();
break;
case 3: printf("ntEnter Value to search = ");
scanf("%d",&a);
search(a);
break;
default: printf("ntMismatch Casen");
printf("tEnter 1 for Continue :");
scanf("%d",&choice);
}
printf("nnt");
display(front);
getch();
}
queue *create(int m)
{
queue *k;
k=((queue*)malloc(sizeof(queue)));
k->info=m;
k->next=NULL;
return k;
}
void addq(queue*n)
{
if(front==NULL)
front=rear=n;
else
{
rear->next=n;
rear=n;
}
}
void display(queue*k)
{
while(k!=NULL)
{
printf("%d->",k->info); 30.
k=k->next;
}
}
void search(intval)
{
queue *p=front;
queue *k;
Intfound =1;
while(p!=NULL)
{
if(p->info==val)
{
printf("ntValueFoundn");
found=0;
break;
}
p=p->next;
}
if(found)
printf("tValueNot Foundn");
}
void delq( )
{
queue *p=front;
front=front->next;
free(p);
}

Contenu connexe

Tendances

Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 

Tendances (20)

Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Arrays
ArraysArrays
Arrays
 
Recursion
RecursionRecursion
Recursion
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
Pointer arithmetic in c
Pointer arithmetic in c Pointer arithmetic in c
Pointer arithmetic in c
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
Heapsort using Heap
Heapsort using HeapHeapsort using Heap
Heapsort using Heap
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Arrays
ArraysArrays
Arrays
 
stack presentation
stack presentationstack presentation
stack presentation
 
Recursion
RecursionRecursion
Recursion
 
Space complexity
Space complexitySpace complexity
Space complexity
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 

En vedette

Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
SANTOSH RATH
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
Srikanth
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
Navtar Sidhu Brar
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
Aakash deep Singhal
 

En vedette (20)

Data structure lab 03ameer hamza
Data structure lab 03ameer hamzaData structure lab 03ameer hamza
Data structure lab 03ameer hamza
 
Data Structures and Algorithms made Easy (Cover Page)
Data Structures and Algorithms made Easy (Cover Page)Data Structures and Algorithms made Easy (Cover Page)
Data Structures and Algorithms made Easy (Cover Page)
 
Assignment
AssignmentAssignment
Assignment
 
C program
C programC program
C program
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
Data structures lab c programs
Data structures lab  c programsData structures lab  c programs
Data structures lab c programs
 
Data structures and algorithms made easy
Data structures and algorithms made easyData structures and algorithms made easy
Data structures and algorithms made easy
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
 
Lab manual of C++
Lab manual of C++Lab manual of C++
Lab manual of C++
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Data structures lab manual
Data structures lab manualData structures lab manual
Data structures lab manual
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Data structures
Data structuresData structures
Data structures
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 

Similaire à Data Structure Project File

Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
SANTOSH RATH
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
herminaherman
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
saneshgamerz
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx
reddy19841
 

Similaire à Data Structure Project File (20)

Final ds record
Final ds recordFinal ds record
Final ds record
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
 
Arrays Fundamentals Unit II
Arrays  Fundamentals Unit IIArrays  Fundamentals Unit II
Arrays Fundamentals Unit II
 
C-programs
C-programsC-programs
C-programs
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
01 list using array
01 list using array01 list using array
01 list using array
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Examples sandhiya class'
Examples sandhiya class'Examples sandhiya class'
Examples sandhiya class'
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx
 

Dernier

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Dernier (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
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");
  • 6. for(i=0;i<n;i++) 04. { printf("%dt",a[i]); } first=0; last= n-1; while(first<=last) { mid=(first+last)/2; if(j<a[mid]) { last=mid-1; } else if(j>a[mid]) { first=mid+1; } else if(j==a[mid]) { printf("nntElement %d Is Found AtLocation %dn",j,mid+1); yn=0; break; } } if(yn==1) { j=-1; printf("nntElement %d Is NotIn This Array",j); } }
  • 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
  • 8. printf("ntThe given matrix is:nnt"); 06. for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d",A[i][j]); printf("t"); } printf("nnt"); } for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(A[i][j]!=0) { B[s][0]=A[i][j]; B[s][1]=i; B[s][2]=j; s++; } } } printf("ntThesparsematrix is given by:nn"); printf("tValuetRowtColumnnnt"); for(i=0;i<s;i++) { for(j=0;j<3;j++) { printf("%d",B[i][j]); printf("t"); } printf("nnt"); } getch(); }
  • 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);
  • 11. printf("nt"); if(first!=NULL) { t=first; while(t!=NULL) { if(t->roll==r) { k=(structstudent*)malloc(sizeof(structstudent)); printf("ntRoll NotttNamen"); printf("nt%dttt%s",t->roll,t->name); printf("nntEnter The Name Of The Student : "); scanf("%s",k->name) ; printf("ntEnter The Roll No Of The Student : "); scanf("%d",&k->roll); k->next=t->next; t->next=k; flag=1; break; } t=t->next; } if(flag==0) printf("ntThe Element Not Found!!!"); } else printf("tElement Not Found "); } void del() { struct student*back,*t,*k; int r; int flag=0; if(first!=NULL) {
  • 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)
  • 19. { 17. start=k; rear=k; } else { k->next=start; start->prev=k; start=k; } } void del() { employee *temp; if(start==NULL) return; else if (rear->prev==NULL) { temp=rear; start=rear=NULL; } else { temp=rear; rear=rear->prev; rear->next=NULL; free(temp); printf("ntNodeDeletednt"); } }
  • 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;
  • 23. } while(k!=start); } void addbeg(node*k) { node *n=start; if(start==NULL) { start=k; start->next=start; } else { while(n->next!=start) n=n->next; k->next=start; start=k; n->next=start; } } node *del(node *start) { node *p,*q; p=start; if(p==NULL) { printf("ntListIs Emptyn"); } else { while(p->next!=rear) { q=p; p=p->next; }
  • 25. 23. Create a stack and performPop, Push, Traverseoperations on the stack using Linear Linked list. Source Code: #include<stdio.h> #include<conio.h> #include<stdlib.h> structstack { int info; struct stack *next; } *top,*rear,*k; typedef structstack stack; stack *create(int); void push(stack *); void display(stack *); void peep(int); void pop(); void main() { int m=8,a,choice1; stack *p; top=NULL; printf("ntNAME- Devesh Kumarnt"); printf("ntNorthern India Engineering Collegent"); printf("nt"); printf("ntPleasePress Enter To Continuent"); Experiment No - 6
  • 26. getch(); printf("ntEnter Eight Numbersn"); while(m--) { printf("nt"); scanf("%d",&a); p=create(a); push(p); } printf("nt"); dispaly(top); printf("nt"); do { printf("ntEnter 1 To PUSHnt"); printf("ntEnter 2 To POPnt"); printf("ntEnter 3 To SEARCHnt"); printf("ntEnter Your Choice :"); scanf("%d",&m); switch(m) { case 1: printf("ntEnter A Value -"); scanf("%d",&m); printf("n"); p=create(m); push(p); break; case 2: printf("n"); pop(); break; case 3: printf("ntEnter Value To Search -"); scanf("%d",&a); printf("nn");
  • 27. peep(a); break; default: printf("ntYou HaveEntered Wrong Choicen"); } printf("t"); dispaly(top); printf("nt"); printf("ntEnter 1 To Continue :"); scanf("%d",&choice1); } while(choice1==1); getch(); } stack *create(int m) { stack *k; k=((stack *)malloc(sizeof(stack))); k->info=m; k->next=NULL; return k; } void push(stack *n) { if(top==NULL) { top=n; } else { n->next=top; top=n; } }
  • 28. dispaly(stack *k) 26. { while(k!=NULL) { printf("%d->",k->info); k=k->next; } } void peep(int val) { stack *p=top; stack *k; int found =1; while(p!=NULL) { if(p->info==val) { printf("tValueFoundnn"); found=0; break; } p=p->next; } if(found) printf("ntValueNot Found"); } void pop( ) { stack *k=top; top=top->next; free(k); }
  • 29. 27. Create a Linear Queue using Linked Listand implement different operations such as Insert, Delete, and Display the queue elements. Source Code: #include<stdio.h> #include<conio.h> #include<stdlib.h> structqueue { int info; structqueue *next; } *front,*rear,*k; typedef structqueue queue; queue *create(int); void addq(queue*); void delq(); void display(queue*); void search(int); void main() { int m=8,a,choice; queue *p; front=rear=NULL; printf("ntNAME - Devesh Kumarn"); printf("ntNorthern India Engineering Collegen"); printf("ntPress a key : nt"); Experiment No - 7
  • 30. getch(); printf("n"); printf("ntEnter Eight Numbersn"); printf("nn"); while(m--) { printf("t"); scanf("%d",&a); p=create(a); addq(p); } printf("t"); printf("nnt"); display(front); printf("nntMENUn"); printf("nntEnter your choicen"); printf("ntTo Add Node, Enter 1 nnt"); printf("ntTo Delete Node, Enter 2nnt"); printf("ntTo Search Value, Enter 3nnt"); scanf("%d",&m); switch(m) { case 1: printf("nntEnter a Value = n"); scanf("%d",&m); p=create(m); addq(p); break; case 2: delq(); break; case 3: printf("ntEnter Value to search = "); scanf("%d",&a); search(a);
  • 31. break; default: printf("ntMismatch Casen"); printf("tEnter 1 for Continue :"); scanf("%d",&choice); } printf("nnt"); display(front); getch(); } queue *create(int m) { queue *k; k=((queue*)malloc(sizeof(queue))); k->info=m; k->next=NULL; return k; } void addq(queue*n) { if(front==NULL) front=rear=n; else { rear->next=n; rear=n; } } void display(queue*k) { while(k!=NULL) {
  • 32. printf("%d->",k->info); 30. k=k->next; } } void search(intval) { queue *p=front; queue *k; Intfound =1; while(p!=NULL) { if(p->info==val) { printf("ntValueFoundn"); found=0; break; } p=p->next; } if(found) printf("tValueNot Foundn"); } void delq( ) { queue *p=front; front=front->next; free(p); }