×
I'm working hard to be someone I'll be proud of.
--Your friends at LectureNotes
Close

Data Structure using C

by Tulasi Miriyala
Type: PracticalDownloads: 3Views: 123Uploaded: 4 months agoAdd to Favourite

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Tulasi Miriyala
Tulasi Miriyala
DATA STRUCTURES AND PROGRAMMING LAB INDEX S. No Date Name Of The Program 1 06-09-16 Write a program for sorting a list using Bubble sort and then apply binary search. 1-4 2 19-09-16 Write a program to implement the operations on stacks. 5-9 3 27-09-16 Write a program to implement the operations on circular queues. 10-15 4 24-10-16 Write a program for evaluating a given postfix expression using stack. 16-19 5 31-10-16 Write a program for converting a given infix expression to postfix form using stack. 20-24 6 08-11-16 Write a program for implementing the operations of a priority queue using dynamic allocation. 25-31 7 13-11-16 Write a program for the representation of polynomials using circular linked list and for the addition of two such polynomials 32-40 8 21-11-16 Write a program for quick sort 41-44 9 29-11-16 Write a program for Merge sort. 45-48 10 05-12-16 Write a program for Heap sort 49-52 11 26-12-16 Write a program to create a binary search tree and for implementing the in order, preorder, post order traversal using recursion 53-60 1 Pg. No Rema rks
DATA STRUCTURES AND PROGRAMMING LAB 1) Write a program for sorting a list using Bubble sort and then apply binary search. Aim: To execute a program for sorting a list using Bubble sort and then apply binary search Algorithm: step1 : start step2 : declare the array with the num and size and array[100] step3 : declare the variables i,j,l,num,temp,keynum,low,mid,high. step4 : enter the „num‟ value with scanf function step5 : enter the elements of the array with using for loop form i=0to i<num step6 : print the elements of the array with using for loop form i=0 to i<num step7 : write the code for bubble sort step8 : with using for loop first element of the array will compare with the second element and the comparison process will be continued to the last element of the array step9 : every two elements and swapped if element 1>element2 step10 : total array will be sorted srep11 : enter „keynum‟ value with using scanf function step12 : search for „keynum‟value in the sorted array with using for loop step13 : print “search successful” when keynum value is in the array and print “location of the “second element” else print “search failed” step14: stop 2
DATA STRUCTURES AND PROGRAMMING LAB Program: #include <stdio.h> void main() { int array[100]; inti, j, l, num, temp, keynum; int low, mid, high; clrscr(); printf("Enter the value of num \n"); scanf("%d",&num); printf("Enter the elements one by one \n"); for (i = 0; i<num; i++) { scanf("%d", &array[i]); } printf("Input array elements \n"); for (i = 0; i<num; i++) { printf("%d\n", array[i]); } /* Bubble sorting begins */ for (i = 0; i<num; i++) { for (j = 0; j < (num - i - 1); j++) { if (array[j] > array[j + 1]) { temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; } } } printf("Sorted array is...\n"); for (i = 0; i<num; i++) { printf("%d\n", array[i]); } printf("Enter the element to be searched \n"); scanf("%d", &keynum); /* Binary searching begins */ low = 1; high = num; do { mid = (low + high) / 2; if (keynum< array[mid]) 3
DATA STRUCTURES AND PROGRAMMING LAB high = mid - 1; else if (keynum> array[mid]) low = mid + 1; } while (keynum != array[mid] && low <= high); if (keynum == array[mid]) { printf("SEARCH SUCCESSFUL \n"); for(l=0;l<num;l++) { if(keynum==array[l]) { printf("Location of searched element:%d",l+1); } } } else { printf("SEARCH FAILED \n"); } getch(); } Output: 4

Lecture Notes