SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
DATA STRUCTURE USING C & C++
SUBMITTED TO: SUBMITTED BY:
LECT. ABHISHEK KUMAR MUSTKEEM
ADD.NO.:14S121
BRANCH: 5 CS.
DIGAMBER JAIN POLYTECHNIC BARAUT BAGHPAT
Admission no.:14S121
Page 1
INTRODUCTION OF DATA STRUCTURE:
Data structure is a particular way of organizing data in a computer so that it can be used
efficiently. Data structures can implement one or more particular abstract data types (ADT),
which specify the operations that can be performed on a data structure and the computational
complexity of those operations. In comparison, a data structure is a concrete implementation
of the specification provided by an ADT.
REQUIREMENT OF DSU C&C++ (TURBO C):
Hardware Requirement:
 IBM-Intel Pentium 4 or above.
 Minimum of 512 MB RAM.
 One 1 GB Free Hard Disk.
 Keyboard and Mouse.
 A CD-ROM drive or USB port.
Software Requirement:
 Operating system- Window 95 or higher.
 Turbo C & C++ or Dev-Cpp.
Admission no.:14S121
Page 2
Setup of Turbo C++:
Step 1:
Download Turbo C from “https://turboc.codeplex.com.”
Step 2:
Click setup.exe file.
Step 3:
Click next.
Admission no.:14S121
Page 3
Step 4:
Accept license agreement and click next.
Step 5:
Click install.
Admission no.:14S121
Page 4
Step 6:
Click finish.
Program 1: WAP in C to print “Hello World”.
#include<stdio.h>
#include<conio.h>
Void main()
{
printf(“Hello World”);
getch();
}
Output:
Admission No.: 14S121
Program 2: Write a Program to Implement Linked List.
Code:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
void main()
{
struct node
{
intnum;
struct node *ptr;
};
typedefstruct node NODE;
NODE *head, *first, *temp = 0;
int count = 0;
int choice = 1;
first = 0;
while (choice)
{
head = (NODE *)malloc(sizeof(NODE));
printf("Enter the data itemn");
scanf("%d", &head->num);
if (first != 0)
{
temp->ptr = head;
temp = head;
}
else
first = temp = head;
}
fflush(stdin);
printf("Do you want to continue(Type 0 or 1)?n");
scanf("%d", &choice);
}
temp->ptr = 0;
/* reset temp to the beginning */
temp = first;
printf("n status of the linked list isn");
while (temp != 0)
Admission No.: 14S121
{
printf("%d=>", temp->num);
count++;
temp = temp ->ptr;
}
printf("NULLn");
printf("No. of nodes in the list = %dn", count);
getch();
}
Output:
Admission No.: 14S121
Practical 3: Write a program to Implement stack operations Push & Pop.
Code:
#include <stdio.h>
#include <stdlib.h>
int stack[5];
void push();
int pop();
void traverse();
int is_empty();
int top_element();
int top = 0;
int main()
{
int element, choice;
for (;;)
{
printf("Stack Operations.n");
printf("1. Insert into stack (Push operation).n");
printf("2. Delete from stack (Pop operation).n");
printf("3. Print top element of stack.n");
printf("4. Check if stack is empty.n");
printf("5. Traverse stack.n");
printf("6. Exit.n");
printf("Enter your choice.n");
scanf("%d",&choice);
switch (choice)
{
case 1:
if (top == 5)
printf("Error: Overflownn");
else {
printf("Enter the value to insert.n");
scanf("%d", &element);
push(element);
}
break;
case 2:
if (top == 0)
printf("Error: Underflow.nn");
else {
element = pop();
printf("Element removed from stack is %d.n", element);
Admission No.: 14S121
}
break;
case 3:
if (!is_empty()) {
element = top_element();
printf("Element at the top of stack is %dnn", element);
}
else
printf("Stack is empty.nn");
break;
case 4:
if (is_empty())
printf("Stack is empty.nn");
else
printf("Stack is not empty.nn");
break;
case 5:
traverse();
break;
case 6:
exit(0);
}
}
}
void push(int value) {
stack[top] = value;
top++;
}
int pop() {
top--;
return stack[top];
}
void traverse() {
int d;
if (top == 0) {
printf("Stack is empty.nn");
return;
}
printf("There are %d elements in stack.n", top);
for (d = top - 1; d >= 0; d--)
printf("%dn", stack[d]);
printf("n");
}
Admission No.: 14S121
intis_empty() {
if (top == 0)
return 1;
else
return 0;
}
inttop_element() {
return stack[top-1];
getch();
}
Output:
Admission No.: 14S121
Practical 4: Write a Program to Implement Queue Operations Insertion &
Deletion.
Code:
#include <stdio.h>
#include <stdlib.h>
#define QUEUESIZE 10
int queue[QUEUESIZE], f=0, r=-1;
// Check if queue is full
intqueuefull() {
if(r == QUEUESIZE - 1) {
return 1;
}
return 0;
}
// Check if the queue is empty
intqueueempty() {
if(f > r) {
return 1;
}
return 0;
}
// Show queue content
intqueueshow() {
inti;
if(queueempty()) {
Admission No.: 14S121
printf(" n The queue is emptyn");
} else {
printf("Start->");
for(i=f; i<=r; i++) {
printf("%d ", queue[i]);
}
printf("<-End");
}
return 0;
}
// Perform an insert operation.
intqueueinsert(intoneelement) {
if(queuefull()) {
printf("nn Overflow!!!!nn");
} else {
++r;
queue[r] = oneelement;
}
return 0;
}
// Perform a delete operation
intqueuedelete() {
intelem;
if(queueempty()) {
printf(" n The queue is emptyn");
return(-1);
} else {
Admission No.: 14S121
elem=queue[f];
f=f+1;
return(elem);
}
}
int main() {
int option, element;
charch;
do {
printf("n Press 1-Insert, 2-Delete, 3-Show, 4-Exitn");
printf("n Your selection? ");
scanf("%d",&option);
switch(option) {
case 1:
printf("nnContent to be Inserted?");
scanf("%d",&element);
queueinsert(element);
break;
case 2:
element=queuedelete();
if( element != -1 ) {
printf("nnDeleted element (with content %d) n",element);
}
break;
case 3:
printf("nnStatus of the queuenn");
queueshow();
Admission No.: 14S121
break;
case 4:
printf("nn Ending the program nn");
break;
default:
printf("nnInvalid option, please retry! nn");
break;
}
} while(option != 4);
getch();
return 0;
}
Output:
Admission No.: 14S121
Practical 5: Write a Program to Implement Insertion Sorting.
Code:
#include <stdio.h>
int main()
{
int n, array[1000], c, d, t;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d integersn", n);
for (c = 0; c < n; c++) {
scanf("%d", &array[c]);
}
for (c = 1 ; c <= n - 1; c++) {
d = c;
while ( d > 0 && array[d] < array[d-1]) {
t = array[d];
array[d] = array[d-1];
array[d-1] = t;
d--;
}
}
printf("Sorted list in ascending order:n");
for (c = 0; c <= n - 1; c++) {
printf("%dn", array[c]);
}
getch();
return 0;
}
Admission No.: 14S121
Output:
Admission No.: 14S121
Practical 6:Write a Program to Implement Bubble Sorting.
Code:
#include <stdio.h>
int main()
{
int array[100], n, c, d, swap;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d integersn", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1]) /* For decreasing order use < */
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
printf("Sorted list in ascending order:n");
for ( c = 0 ; c < n ; c++ )
printf("%dn", array[c]);
getch();
return 0;
}
Admission No.: 14S121
Output:
Admission No.: 14S121
Practical 7: Write a Program to Implement Quick Sorting.
Code:
#include<stdio.h>
#include<conio.h>
//quick Sort function to Sort Integer array list
void quicksort(int array[], intfirstIndex, intlastIndex)
{
//declaaring index variables
intpivotIndex, temp, index1, index2;
if(firstIndex<lastIndex)
{
//assigninh first element index as pivot element
pivotIndex = firstIndex;
index1 = firstIndex;
index2 = lastIndex;
//Sorting in Ascending order with quick sort
while(index1 < index2)
{
while(array[index1] <= array[pivotIndex] && index1 <lastIndex)
{
index1++;
}
while(array[index2]>array[pivotIndex])
{
index2--;
}
if(index1<index2)
{
//Swapping opertation
Admission No.: 14S121
temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}
}
//At the end of first iteration, swap pivot element with index2 element
temp = array[pivotIndex];
array[pivotIndex] = array[index2];
array[index2] = temp;
//Recursive call for quick sort, with partiontioning
quicksort(array, firstIndex, index2-1);
quicksort(array, index2+1, lastIndex);
}
}
int main()
{
//Declaring variables
int array[100],n,i;
//Number of elements in array form user input
printf("Enter the number of element you want to Sort : ");
scanf("%d",&n);
//code to ask to enter elements from user equal to n
printf("Enter Elements in the list : ");
for(i = 0; i< n; i++)
{
scanf("%d",&array[i]);
}
//calling quickSort function defined above
quicksort(array,0,n-1);
Admission No.: 14S121
//print sorted array
printf("Sorted elements: ");
for(i=0;i<n;i++)
printf(" %d",array[i]);
getch();
return 0;
}
Output:
Admission No.: 14S121
Practical 8: Write a Program to Implement Merge Sorting.
Code:
#include<stdio.h>
#define MAX 50
voidmergeSort(intarr[],intlow,intmid,int high);
void partition(intarr[],intlow,int high);
int main()
{
int merge[MAX],i,n;
printf("Enter the total number of elements: ");
scanf("%d",&n);
printf("Enter the elements which to be sort: ");
for(i=0;i<n;i++){
scanf("%d",&merge[i]);
}
partition(merge,0,n-1);
printf("After merge sorting elements are: ");
for(i=0;i<n;i++){
printf("%d ",merge[i]);
}
return 0;
}
void partition(intarr[],intlow,int high){
int mid;
if(low<high){
mid=(low+high)/2;
partition(arr,low,mid);
partition(arr,mid+1,high);
mergeSort(arr,low,mid,high);
Admission No.: 14S121
}
}
voidmergeSort(intarr[],intlow,intmid,int high){
inti,m,k,l,temp[MAX];
l=low;
i=low;
m=mid+1;
while((l<=mid)&&(m<=high)){
if(arr[l]<=arr[m]){
temp[i]=arr[l];
l++;
}
else{
temp[i]=arr[m];
m++;
}
i++;
}
if(l>mid){
for(k=m;k<=high;k++){
temp[i]=arr[k];
i++;
}
}
else{
for(k=l;k<=mid;k++){
temp[i]=arr[k];
Admission No.: 14S121
i++;
}
}
for(k=low;k<=high;k++){
arr[k]=temp[k];
}
}
Output:
Admission No.: 14S121
Practical 9:Write a Program to Implement Heap Sorting.
Code:
#include<stdio.h>
#include<conio.h>
void manage(int *, int);
voidheapsort(int *, int, int);
int main()
{
intarr[20];
inti,j,size,tmp,k;
printf("nt------- Heap sorting method -------nn");
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
for(i=1; i<=size; i++)
{
printf("Enter %d element : ",i);
scanf("%d",&arr[i]);
manage(arr,i);
}
j=size;
for(i=1; i<=j; i++)
{
tmp=arr[1];
arr[1]=arr[size];
arr[size]=tmp;
size--;
heapsort(arr,1,size);
}
printf("nt------- Heap sorted elements -------nn");
size=j;
for(i=1; i<=size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void manage(int *arr, inti)
{
inttmp;
tmp=arr[i];
while((i>1)&&(arr[i/2]<tmp))
{
arr[i]=arr[i/2];
Admission No.: 14S121
i=i/2;
}
arr[i]=tmp;
}
voidheapsort(int *arr, inti, int size)
{
inttmp,j;
tmp=arr[i];
j=i*2;
while(j<=size)
{
if((j<size)&&(arr[j]<arr[j+1]))
j++;
if(arr[j]<arr[j/2])
break;
arr[j/2]=arr[j];
j=j*2;
}
arr[j/2]=tmp;
}
Output:

Mais conteúdo relacionado

Mais procurados

Event managementsystem
Event managementsystemEvent managementsystem
Event managementsystemPraveen Jha
 
Hospital Management system Database design
Hospital Management system Database designHospital Management system Database design
Hospital Management system Database designElias Dinsa
 
Wedding PlannerPresentation
Wedding PlannerPresentationWedding PlannerPresentation
Wedding PlannerPresentationAzmina Papeya
 
Software Engineering- ERD DFD Decision Tree and Table
Software Engineering- ERD DFD Decision Tree and TableSoftware Engineering- ERD DFD Decision Tree and Table
Software Engineering- ERD DFD Decision Tree and TableNishu Rastogi
 
Student management system
Student management systemStudent management system
Student management systemAmit Gandhi
 
System Analysis and Design Project
System Analysis and Design ProjectSystem Analysis and Design Project
System Analysis and Design ProjectSiddharth Shah
 
Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Gurpreet singh
 
Student Management System best PPT
Student Management System best PPTStudent Management System best PPT
Student Management System best PPTDheeraj Kumar tiwari
 
Project management System-PPT.pdf
Project management System-PPT.pdfProject management System-PPT.pdf
Project management System-PPT.pdfMCube2
 
S/4 HANA Cash Management - Change Bank Account
S/4 HANA Cash Management - Change Bank AccountS/4 HANA Cash Management - Change Bank Account
S/4 HANA Cash Management - Change Bank AccountDinesh Kumar
 
Entity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalizationEntity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalizationSatya Pal
 
Event management system
Event management systemEvent management system
Event management systemD Yogendra Rao
 
computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)Nitish Yadav
 
Introduction to Oracle Database
Introduction to Oracle DatabaseIntroduction to Oracle Database
Introduction to Oracle Databasepuja_dhar
 
Hospital management system (php project) web engineering
Hospital management system (php project) web engineeringHospital management system (php project) web engineering
Hospital management system (php project) web engineeringIftikhar Ahmad
 

Mais procurados (20)

Event managementsystem
Event managementsystemEvent managementsystem
Event managementsystem
 
Hospital Management system Database design
Hospital Management system Database designHospital Management system Database design
Hospital Management system Database design
 
Wedding PlannerPresentation
Wedding PlannerPresentationWedding PlannerPresentation
Wedding PlannerPresentation
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
 
Software Engineering- ERD DFD Decision Tree and Table
Software Engineering- ERD DFD Decision Tree and TableSoftware Engineering- ERD DFD Decision Tree and Table
Software Engineering- ERD DFD Decision Tree and Table
 
Event management system
Event management systemEvent management system
Event management system
 
Student management system
Student management systemStudent management system
Student management system
 
Library Management System ppt
Library Management System pptLibrary Management System ppt
Library Management System ppt
 
System Analysis and Design Project
System Analysis and Design ProjectSystem Analysis and Design Project
System Analysis and Design Project
 
Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Student Management System best PPT
Student Management System best PPTStudent Management System best PPT
Student Management System best PPT
 
Project management System-PPT.pdf
Project management System-PPT.pdfProject management System-PPT.pdf
Project management System-PPT.pdf
 
S/4 HANA Cash Management - Change Bank Account
S/4 HANA Cash Management - Change Bank AccountS/4 HANA Cash Management - Change Bank Account
S/4 HANA Cash Management - Change Bank Account
 
Entity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalizationEntity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalization
 
Event management system
Event management systemEvent management system
Event management system
 
computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)
 
Introduction to Oracle Database
Introduction to Oracle DatabaseIntroduction to Oracle Database
Introduction to Oracle Database
 
File in C language
File in C languageFile in C language
File in C language
 
Hospital management system (php project) web engineering
Hospital management system (php project) web engineeringHospital management system (php project) web engineering
Hospital management system (php project) web engineering
 

Semelhante a DSU C&C++ Practical File Diploma

Semelhante a DSU C&C++ Practical File Diploma (20)

DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Data struture lab
Data struture labData struture lab
Data struture lab
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
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
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
Qprgs
QprgsQprgs
Qprgs
 
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 DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
Double linked list
Double linked listDouble linked list
Double linked list
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
7 functions
7  functions7  functions
7 functions
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Array Cont
Array ContArray Cont
Array Cont
 
Pnno
PnnoPnno
Pnno
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 

Último

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
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.pdfPoh-Sun Goh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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.pptxMaritesTamaniVerdade
 
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).pptxVishalSingh1417
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
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.pdfAdmir Softic
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Último (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet 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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
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
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
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
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

DSU C&C++ Practical File Diploma

  • 1. DATA STRUCTURE USING C & C++ SUBMITTED TO: SUBMITTED BY: LECT. ABHISHEK KUMAR MUSTKEEM ADD.NO.:14S121 BRANCH: 5 CS. DIGAMBER JAIN POLYTECHNIC BARAUT BAGHPAT
  • 2. Admission no.:14S121 Page 1 INTRODUCTION OF DATA STRUCTURE: Data structure is a particular way of organizing data in a computer so that it can be used efficiently. Data structures can implement one or more particular abstract data types (ADT), which specify the operations that can be performed on a data structure and the computational complexity of those operations. In comparison, a data structure is a concrete implementation of the specification provided by an ADT. REQUIREMENT OF DSU C&C++ (TURBO C): Hardware Requirement:  IBM-Intel Pentium 4 or above.  Minimum of 512 MB RAM.  One 1 GB Free Hard Disk.  Keyboard and Mouse.  A CD-ROM drive or USB port. Software Requirement:  Operating system- Window 95 or higher.  Turbo C & C++ or Dev-Cpp.
  • 3. Admission no.:14S121 Page 2 Setup of Turbo C++: Step 1: Download Turbo C from “https://turboc.codeplex.com.” Step 2: Click setup.exe file. Step 3: Click next.
  • 4. Admission no.:14S121 Page 3 Step 4: Accept license agreement and click next. Step 5: Click install.
  • 5. Admission no.:14S121 Page 4 Step 6: Click finish. Program 1: WAP in C to print “Hello World”. #include<stdio.h> #include<conio.h> Void main() { printf(“Hello World”); getch(); } Output:
  • 6. Admission No.: 14S121 Program 2: Write a Program to Implement Linked List. Code: #include <stdio.h> #include <malloc.h> #include <stdlib.h> void main() { struct node { intnum; struct node *ptr; }; typedefstruct node NODE; NODE *head, *first, *temp = 0; int count = 0; int choice = 1; first = 0; while (choice) { head = (NODE *)malloc(sizeof(NODE)); printf("Enter the data itemn"); scanf("%d", &head->num); if (first != 0) { temp->ptr = head; temp = head; } else first = temp = head; } fflush(stdin); printf("Do you want to continue(Type 0 or 1)?n"); scanf("%d", &choice); } temp->ptr = 0; /* reset temp to the beginning */ temp = first; printf("n status of the linked list isn"); while (temp != 0)
  • 7. Admission No.: 14S121 { printf("%d=>", temp->num); count++; temp = temp ->ptr; } printf("NULLn"); printf("No. of nodes in the list = %dn", count); getch(); } Output:
  • 8. Admission No.: 14S121 Practical 3: Write a program to Implement stack operations Push & Pop. Code: #include <stdio.h> #include <stdlib.h> int stack[5]; void push(); int pop(); void traverse(); int is_empty(); int top_element(); int top = 0; int main() { int element, choice; for (;;) { printf("Stack Operations.n"); printf("1. Insert into stack (Push operation).n"); printf("2. Delete from stack (Pop operation).n"); printf("3. Print top element of stack.n"); printf("4. Check if stack is empty.n"); printf("5. Traverse stack.n"); printf("6. Exit.n"); printf("Enter your choice.n"); scanf("%d",&choice); switch (choice) { case 1: if (top == 5) printf("Error: Overflownn"); else { printf("Enter the value to insert.n"); scanf("%d", &element); push(element); } break; case 2: if (top == 0) printf("Error: Underflow.nn"); else { element = pop(); printf("Element removed from stack is %d.n", element);
  • 9. Admission No.: 14S121 } break; case 3: if (!is_empty()) { element = top_element(); printf("Element at the top of stack is %dnn", element); } else printf("Stack is empty.nn"); break; case 4: if (is_empty()) printf("Stack is empty.nn"); else printf("Stack is not empty.nn"); break; case 5: traverse(); break; case 6: exit(0); } } } void push(int value) { stack[top] = value; top++; } int pop() { top--; return stack[top]; } void traverse() { int d; if (top == 0) { printf("Stack is empty.nn"); return; } printf("There are %d elements in stack.n", top); for (d = top - 1; d >= 0; d--) printf("%dn", stack[d]); printf("n"); }
  • 10. Admission No.: 14S121 intis_empty() { if (top == 0) return 1; else return 0; } inttop_element() { return stack[top-1]; getch(); } Output:
  • 11. Admission No.: 14S121 Practical 4: Write a Program to Implement Queue Operations Insertion & Deletion. Code: #include <stdio.h> #include <stdlib.h> #define QUEUESIZE 10 int queue[QUEUESIZE], f=0, r=-1; // Check if queue is full intqueuefull() { if(r == QUEUESIZE - 1) { return 1; } return 0; } // Check if the queue is empty intqueueempty() { if(f > r) { return 1; } return 0; } // Show queue content intqueueshow() { inti; if(queueempty()) {
  • 12. Admission No.: 14S121 printf(" n The queue is emptyn"); } else { printf("Start->"); for(i=f; i<=r; i++) { printf("%d ", queue[i]); } printf("<-End"); } return 0; } // Perform an insert operation. intqueueinsert(intoneelement) { if(queuefull()) { printf("nn Overflow!!!!nn"); } else { ++r; queue[r] = oneelement; } return 0; } // Perform a delete operation intqueuedelete() { intelem; if(queueempty()) { printf(" n The queue is emptyn"); return(-1); } else {
  • 13. Admission No.: 14S121 elem=queue[f]; f=f+1; return(elem); } } int main() { int option, element; charch; do { printf("n Press 1-Insert, 2-Delete, 3-Show, 4-Exitn"); printf("n Your selection? "); scanf("%d",&option); switch(option) { case 1: printf("nnContent to be Inserted?"); scanf("%d",&element); queueinsert(element); break; case 2: element=queuedelete(); if( element != -1 ) { printf("nnDeleted element (with content %d) n",element); } break; case 3: printf("nnStatus of the queuenn"); queueshow();
  • 14. Admission No.: 14S121 break; case 4: printf("nn Ending the program nn"); break; default: printf("nnInvalid option, please retry! nn"); break; } } while(option != 4); getch(); return 0; } Output:
  • 15. Admission No.: 14S121 Practical 5: Write a Program to Implement Insertion Sorting. Code: #include <stdio.h> int main() { int n, array[1000], c, d, t; printf("Enter number of elementsn"); scanf("%d", &n); printf("Enter %d integersn", n); for (c = 0; c < n; c++) { scanf("%d", &array[c]); } for (c = 1 ; c <= n - 1; c++) { d = c; while ( d > 0 && array[d] < array[d-1]) { t = array[d]; array[d] = array[d-1]; array[d-1] = t; d--; } } printf("Sorted list in ascending order:n"); for (c = 0; c <= n - 1; c++) { printf("%dn", array[c]); } getch(); return 0; }
  • 17. Admission No.: 14S121 Practical 6:Write a Program to Implement Bubble Sorting. Code: #include <stdio.h> int main() { int array[100], n, c, d, swap; printf("Enter number of elementsn"); scanf("%d", &n); printf("Enter %d integersn", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); for (c = 0 ; c < ( n - 1 ); c++) { for (d = 0 ; d < n - c - 1; d++) { if (array[d] > array[d+1]) /* For decreasing order use < */ { swap = array[d]; array[d] = array[d+1]; array[d+1] = swap; } } } printf("Sorted list in ascending order:n"); for ( c = 0 ; c < n ; c++ ) printf("%dn", array[c]); getch(); return 0; }
  • 19. Admission No.: 14S121 Practical 7: Write a Program to Implement Quick Sorting. Code: #include<stdio.h> #include<conio.h> //quick Sort function to Sort Integer array list void quicksort(int array[], intfirstIndex, intlastIndex) { //declaaring index variables intpivotIndex, temp, index1, index2; if(firstIndex<lastIndex) { //assigninh first element index as pivot element pivotIndex = firstIndex; index1 = firstIndex; index2 = lastIndex; //Sorting in Ascending order with quick sort while(index1 < index2) { while(array[index1] <= array[pivotIndex] && index1 <lastIndex) { index1++; } while(array[index2]>array[pivotIndex]) { index2--; } if(index1<index2) { //Swapping opertation
  • 20. Admission No.: 14S121 temp = array[index1]; array[index1] = array[index2]; array[index2] = temp; } } //At the end of first iteration, swap pivot element with index2 element temp = array[pivotIndex]; array[pivotIndex] = array[index2]; array[index2] = temp; //Recursive call for quick sort, with partiontioning quicksort(array, firstIndex, index2-1); quicksort(array, index2+1, lastIndex); } } int main() { //Declaring variables int array[100],n,i; //Number of elements in array form user input printf("Enter the number of element you want to Sort : "); scanf("%d",&n); //code to ask to enter elements from user equal to n printf("Enter Elements in the list : "); for(i = 0; i< n; i++) { scanf("%d",&array[i]); } //calling quickSort function defined above quicksort(array,0,n-1);
  • 21. Admission No.: 14S121 //print sorted array printf("Sorted elements: "); for(i=0;i<n;i++) printf(" %d",array[i]); getch(); return 0; } Output:
  • 22. Admission No.: 14S121 Practical 8: Write a Program to Implement Merge Sorting. Code: #include<stdio.h> #define MAX 50 voidmergeSort(intarr[],intlow,intmid,int high); void partition(intarr[],intlow,int high); int main() { int merge[MAX],i,n; printf("Enter the total number of elements: "); scanf("%d",&n); printf("Enter the elements which to be sort: "); for(i=0;i<n;i++){ scanf("%d",&merge[i]); } partition(merge,0,n-1); printf("After merge sorting elements are: "); for(i=0;i<n;i++){ printf("%d ",merge[i]); } return 0; } void partition(intarr[],intlow,int high){ int mid; if(low<high){ mid=(low+high)/2; partition(arr,low,mid); partition(arr,mid+1,high); mergeSort(arr,low,mid,high);
  • 23. Admission No.: 14S121 } } voidmergeSort(intarr[],intlow,intmid,int high){ inti,m,k,l,temp[MAX]; l=low; i=low; m=mid+1; while((l<=mid)&&(m<=high)){ if(arr[l]<=arr[m]){ temp[i]=arr[l]; l++; } else{ temp[i]=arr[m]; m++; } i++; } if(l>mid){ for(k=m;k<=high;k++){ temp[i]=arr[k]; i++; } } else{ for(k=l;k<=mid;k++){ temp[i]=arr[k];
  • 25. Admission No.: 14S121 Practical 9:Write a Program to Implement Heap Sorting. Code: #include<stdio.h> #include<conio.h> void manage(int *, int); voidheapsort(int *, int, int); int main() { intarr[20]; inti,j,size,tmp,k; printf("nt------- Heap sorting method -------nn"); printf("Enter the number of elements to sort : "); scanf("%d",&size); for(i=1; i<=size; i++) { printf("Enter %d element : ",i); scanf("%d",&arr[i]); manage(arr,i); } j=size; for(i=1; i<=j; i++) { tmp=arr[1]; arr[1]=arr[size]; arr[size]=tmp; size--; heapsort(arr,1,size); } printf("nt------- Heap sorted elements -------nn"); size=j; for(i=1; i<=size; i++) printf("%d ",arr[i]); getch(); return 0; } void manage(int *arr, inti) { inttmp; tmp=arr[i]; while((i>1)&&(arr[i/2]<tmp)) { arr[i]=arr[i/2];
  • 26. Admission No.: 14S121 i=i/2; } arr[i]=tmp; } voidheapsort(int *arr, inti, int size) { inttmp,j; tmp=arr[i]; j=i*2; while(j<=size) { if((j<size)&&(arr[j]<arr[j+1])) j++; if(arr[j]<arr[j/2]) break; arr[j/2]=arr[j]; j=j*2; } arr[j/2]=tmp; } Output: