You are on page 1of 47

DATA STRUCTURE MANAGEMENT TUTORIAL

// Develop a program to insert, delete, edit element in array

#include<stdio.h> #include<conio.h> #include<stdlib.h> main() { int array[15]; int no_el,i,choice,pos,key,new_el; clrscr(); printf("Enter the no of element :"); scanf("%d",&no_el); for(i=0;i<no_el;i++) { printf("Enter the element : "); scanf("%d",&array[i]); } while(1) { clrscr(); printf("\n 1. Insert \n 2. delete by value \n 3. edit \n 4. display \n 5. exit"); printf("\n Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1:

printf("Enter the position at which you want to insert : "); scanf("%d",&pos); printf("Enter the new element : "); scanf("%d",&new_el); pos--; for(i=no_el-1;i>=pos;i--) array[i+1]=array[i]; array[pos]=new_el; no_el++; break; case 2: printf("Enter the value to be search : "); scanf("%d",&key); for(pos=0;pos<no_el;pos++) { if(array[pos]==key) break; } if(pos==no_el) { printf("Search key not found"); break; } for(i=pos;i<no_el;i++) array[i]=array[i+1]; no_el--; break;

case 3: printf("Enter the position to be edit : "); scanf("%d",&pos); printf("Enter the new value for old position : "); scanf("%d",&array[pos-1]); break; case 4: printf("\n"); for(i=0;i<no_el;i++) printf("\nThe element is %d: %d",i+1,array[i]); break; case 5: return(0);

} getch(); } } // Write simple programs using pointers and arrays

#include<conio.h> #include<stdio.h>

int main() { char *ptr1 = "Darshak"; char *ptr2 = "Divyesh";

h> #include <conio. arr[1] = ptr2. y = 20. z = 30. getch(). clrscr(). printf("\n [%s]\n".char *ptr3 = "Rajnik". arr[0]). int *array[3]. arr[0] = ptr1. int x = 10. } // Write simple programs using array of pointer #include <stdio. arr[2] = ptr3. arr[1]). char* arr[3]. printf("\n [%s]\n". . arr[2]). printf("\n [%s]\n".h> main() { clrscr(). return 0.

*(array[i]). array[1] = &y. for (i=0. } #include<stdio. /* Initializing the stack(i. array[2] = &z. } getch(). i. i++) { printf("The value of %d= %d . array[i]).address is %u\t \n". return 0.h> #include<stdlib. }. i< 3.int i.h> #include<conio. int top.h> #define MAX 50 int size. top=-1) void init_stk(struct stack *st) */ . array[0] = &x.e. /* Defining the stack structure */ struct stack { int AR[MAX]..

} .").."). st->AR[st->top] = num. stack empty).int num) { if(st->top == size-1) { printf("\nStack overflow(i. } st->top++.e. int pop(struct stack *st) { int num.{ st->top=-1. return NULL. stack full).. if(st->top == -1) { printf("\nStack underflow(i. } /* Entering the elements into stack */ void push (struct stack *st.e. } //Deleting an element from the stack. return.

printf("\n").PUSH").i--) printf("\n%d". printf("\n4.QUIT").POP"). for(i=st->top.opt. printf("\n1.val. init_stk(&ptr). } void main() { int ele.st->AR[i]). struct stack ptr. printf("\n2. return num.DISPLAY"). scanf("%d".num=st->AR[st->top]. } void display(struct stack *st) { int i. printf("\nEnter your option : "). while(1) { printf("\n\n\tSTACK PRIMITIVE OPERATIONS"). printf("\nEnter Stack Size :").&size). clrscr().i>=0. . st->top--. printf("\n3.

ele).val)."). printf("\nThe element popped from stack is : %d". case 2: ele=pop(&ptr). break.&opt). default: printf("\nEnter correct option!Try again. */ . switch(opt) { case 1: printf("\nEnter the element into stack:"). display(&ptr).&val). exit(0). } } } /* Develop an algorithm for insert and delete operations of queue and implement using array and pointer data structures.scanf("%d". push(&ptr. case 3: printf("\nThe current stack elements are:"). case 4: getch(). break. break. scanf("%d".

int add_ele(struct q_arr* queue. int a[size]. int ch.k.h> #include<conio. void init(struct q_arr* queue). void display_ele(struct q_arr* queue).#include<stdio.h> #include<alloc.r. int f_que(struct q_arr* queue).h> #define size 10 #define true 1 #define false 0 struct q_arr { int f. /*main function*/ void main() { int ele.int). int num. . int rem_ele(struct q_arr* queue). }. int e_que(struct q_arr* queue).

printf("============================================"). printf("\n\t[2] To remove an element"). scanf("%d". printf("\n\t[1] To insert an element"). } . printf("============================================").struct q_arr *queue = (struct q_arr*)malloc(sizeof(struct q_arr)). add_ele(queue. init(queue). printf("\n\n****IMPLEMENTATION OF QUEUE USING ARRAYS****\n"). printf("\n\t\tMENU\n"). printf("\n\n\t Enter your choice: ").&ch). scanf("%d". printf("\n\t[3] To display all the elements"). break.&ele).ele). switch(ch) { case 1: { printf("\nElement to be inserted:"). while(1) { clrscr(). printf("\n\t[4] Exit").

"). No element can be removed. } break. } case 3: { display_ele(queue).k). getch(). printf("\n%d element is removed\n". } case 4: exit(0). break. getch(). getch(). . } else { printf("\tQueue is Empty.case 2: { if(!e_que(queue)) { k=rem_ele(queue).

"). queue->r = -1. } } } /*end main*/ void init(struct q_arr* queue) { queue->f = 0. getch(). } /* Function to check is the queue is empty*/ int e_que(struct q_arr* queue) { if(queue->num==0) return true. return false. break. queue->num = 0.default: printf("\tInvalid Choice. } /* Function to check if the queue is full*/ int f_que(struct q_arr* queue) { .

if(e_que(queue)) return -9999. } /* Function to remove an element of the queue*/ int rem_ele(struct q_arr* queue) { int j. queue->num++. queue->a[++queue->r] = j. if(queue->r == size . j = queue->a[queue->f++].if(queue->num == size) return true.1) queue->r = -1. .int j) { if(f_que(queue)) return false. if(queue->f == size) queue->f = 0. } /* Function to add an element to the queue*/ int add_ele(struct q_arr* queue. return false. return true.

queue->a[j]).j++) printf("%d\t".j<=queue->r. } printf("\nElements present in the Queue are: ").h> #include<malloc. int del(int).queue->num--. int insert(). } /* Function to display the queue*/ void display_ele(struct q_arr* queue) { int j. if(e_que(queue)) { printf("Queue is Empty. void display(). No records to display."). printf("\n"). } #include<stdio. return. . for(j=queue->f.h> void append(). return j. int insertn(). int search(int).

struct node *first. do { printf("\n Enter the choice \n 1.Insert\n 2.void rev(). scanf("%d". char n[20]. struct node *next.delete\n 3. . //first=last=NULL.&ch).*last. struct node { int a.Search\n 4.Dispaly\n 5. }. int num. clrscr(). int main() { int ch. switch(ch) { case 1: insert().exit\n \n"). char name[20].loc.

temp=(struct node *)malloc(sizeof(struct node)). search(num). case 4: display(). break. del(num). break. case 2: printf("\n enter the value \n").break. break. scanf("%d".&temp->a).&num).&num). return 0. default: break. } int insert() { struct node *temp. case 3: printf("\n enter the value to find \n"). scanf("%d". printf("\n enter the location: "). printf("\n enter value: "). . } }while(ch!=5). scanf("%d".

temp->n).*m. first=temp.scanf("%s". } else { temp->next=first. } display(). while(temp!=NULL) { if(temp->a==num) { if(temp==first) { first=temp->next. } int del(int num) { struct node *temp. return 0. first->next=NULL. temp=first. if(first==NULL) { first=temp. .

return. temp=first. .num). } } else { m=temp. while(temp!=NULL) { if(temp->a==num) { printf("%d is exist". free(temp). } } } int search(int num) { struct node *temp.free(temp). return. temp=temp->next. } else { m->next=temp->next.

temp=temp->next.temp->n). temp=first.printf("\t its name is %s". } else temp=temp->next.temp->n). temp=(struct node*)malloc(sizeof(struct node)).temp->a. printf("\n"). } if(temp->a!=num) { printf("not exist"). while(temp!=NULL) { printf("%d %s\t". } } void display() { struct node *temp. } . break. } printf("\n").

else if ((r->right != NULL) && (strcmp(p->data. r->data) < 0)) insert(r->left. r->data) < 0)) r->left = p. struct node *w. *stack[20]. if ((r->left == NULL) && (strcmp(p->data. *right. struct node *p) { if ((r->right == NULL) && (strcmp(p->data. p). }.h> struct node { char data[15].h> #include <dos. } void tree(struct node *r. struct node *left. p).#include <stdio. r->data) > 0)) r->right = p. flag. else if ((r->left != NULL) && (strcmp(p->data. int c) { int top.h> #include <string. if (r != NULL) { . r->data) > 0)) insert(r->right. void insert(struct node *r.h> #include <stdlib.

if (c == 2) printf(" %s ". w->data). if (c == 3) printf(" %s ". } printf(" %s ". c). w = w->left. c). } } if (c == 4) { top = 0. w = r.if (c != 4) { if (c == 1) printf(" %s ". tree(r->left. r->data). r->data). flag = 0.1) && (w != NULL)) { while ((flag == 0) && (w->left != NULL)) { stack[top] = w. tree(r->right. top++. while ((top != . if (w->right != NULL) . r->data).

root = NULL. Delete "). *root. Enter"). Search "). *q. i. flag. w = stack[top]. c. flag = 1. char temp = 'N'. *r. . printf("\n 4. Display").{ w = w->right. temp1[15]. printf("\n 2. } } } } void main() { int choice. } else { top--. struct node *s. flag = 0. clrscr(). printf("\n 3. do { printf("\n 1.

printf("\n 5. s->left = NULL. } while (temp == 'y'). &choice). switch (choice) { case 1: printf("***** Data Entry ***** "). scanf("%c". scanf("%s". s). Exit"). else insert(root. scanf("%d". &temp). break. case 2: printf("****** Delete Operation *******\n"). do { s = malloc(sizeof(struct node)). if (root == NULL) root = s. &s->data). printf("\nEnter Data : "). printf("\nEnter Your Elements[y/n] : "). printf("\nEnter Your Choice : "). s->right = NULL. do { .

s = root. scanf("%s". } if (root->right == NULL) root = root->left. i = 2. } if (strcmp(s->data. temp1) == 0) { flag = 1. temp1). if (i == 0) { if (root->right != NULL) { q = root->left. i = 0. flag = 0. s = s->left. root = root->right. temp1) > 0) { r = s. do { if (strcmp(s->data. insert(root. q).printf("\nEnter Element To Be Deleted : "). } .

r->left = s->left. q). &temp). if (s->right != NULL) insert(r. case 3: . } } } } while (flag == 0 && s != NULL). r->right = s->right.else { if (i == 1) { q = s->left. q). if (s->left != NULL) insert(r. scanf("%c". } if (i == 2) { q = s->right. } while (temp == 'y') . printf("\n Delete Any More[Y/N] : "). break.

i = 0. s = root. temp1) == 0) i = 1. do { printf("\n Enter Name To Be Searched"). } if (i == 0) printf("\nElement Not Found\n"). temp1) < 0)s = s>right. if (strcmp(s->data. while (s != NULL && i == 0) { if (strcmp(s->data. } while (temp == 'y') . else printf("\nElement Found\n"). temp1) > 0) s = s->left. case 4: do . printf("\nEnter More Elements[Y/N] : "). &temp). if (strcmp(s->data. break. temp1). scanf("%c".printf("****** Search Operation *******\n"). scanf("%s".

if (root == NULL) printf("Tree Not Started Yet"). scanf("%d".. } // sequential search #include<stdio. printf("\nEnter Your Choice : ").k. getch(). .{ printf( "\n 1. else tree(root.h> void main() { int arr[50]. &c).i. } } while (choice != 5) . Preorder\n 2. Non Recursion \n 5..pos=0. break..l."). Exit"). printf("\n Press Any Key To Continue. Postorder \n 4. c)... } while (c != 5). Inorder \n 3.

i++) { scanf("%d".h> #include<conio.i<l. printf("\nEnter %d elements\n". for(i=0.&l). at position %d\n".h> . } #include<stdio.clrscr().&k).k). printf("Enter limit For SEQUENTIAL SEARCH :.k. for(i=0."). scanf("%d".i++) { if(arr[i]==k) { pos=i+1. break.pos).&arr[i]).l)."). getch(). } } if(pos!=0) printf("%d is found in the list.i<l. } printf("\nEnter a number to be search:. scanf("%d". else printf("%d is not in the list\n".

a[j+1]=temp.i<n-1.&n).i<n. for(i=0. .a[i]). clrscr().mid.i<n. for(i=0.i++) { for(j=0.i++) scanf("%d". for(i=0. int beg.n.j++) { if(a[j+1]<a[j]) { temp=a[j].&a[i]).j<n-i-1. printf("enter the array elements: ").end. a[j]=a[j+1]. scanf("%d". printf("enter the total numbers:").target.i.i++) printf(" %d".temp.j.void main() { int a[10]. } } } printf("the sorted numbers are:"). beg=0.

void main() . while(beg<=end && a[mid]!=target) { if(target<a[mid]) end=mid-1. mid=(beg+end)/2. printf("\nEnter the number to be searched:").TRUE }. } Program of sorting using quick sort through recursion Code: /*Program of sorting using quick sort through recursion*/ #include<stdio.h> #include<conio. } if(a[mid]==target) { printf("\nThe number is found at position %d". mid=(beg+end)/2.end=n-1.mid+1).h> #define MAX 30 enum bool { FALSE. } else { printf("\nThe number is not found").&target). else beg=mid+1. scanf("%d". } getch().

display(a.low. arr[piv]=arr[right].&a[i]).int low. printf("\n").temp. } /*Compare from left to right */ while( arr[piv]>=arr[left] && left!=piv ) left++.i. printf("Enter the number of elements : ").up).i<n.n-1).n-1).right.0.0.&n). scanf("%d".int up) { int piv. arr[piv]=arr[left]. printf("Sorted list is :\n"). for(i=0.n. .i+1).{ int a[MAX]. arr[right]=temp. if(piv==left) pivot_placed=TRUE. printf("\n"). scanf("%d".n-1). if( piv==right ) pivot_placed=TRUE. /*Loop till pivot is placed at proper place in the sublist*/ while(pivot_placed==FALSE) { /*Compare from right to left */ while(arr[piv]<=arr[right] && piv!=right) right--. display(arr. printf("Sublist : "). piv=low.0. /*Take the first element of sublist as piv */ if(low>=up) return. if( arr[piv] < arr[left] ) { temp=arr[piv]. if( arr[piv] > arr[right] ) { temp=arr[piv]. left=low. piv=right. right=up. display(a.left.i++) { printf("Enter element %d : ". } printf("Unsorted list is :\n"). clrscr(). quick(a. enum bool pivot_placed=FALSE. }/*End of main() */ quick(int arr[].

h> # include<malloc. } }/*End of while */ printf("-> Pivot Placed is %d -> ".int low.i<n. } }/*End of for*/ . for(i=low.arr[piv]). tmp->link=NULL. int i.int up) { int i. struct node *link.item.piv+1. display(arr.i++) { printf("Enter element %d : ".*q.low. scanf("%d".&item). for(i=0.arr[i]). }/*End of quick()*/ display(int arr[]. piv=left. quick(arr. printf("\n").piv-1).i<=up. }*start=NULL. scanf("%d". } Program of sorting using radix sort Code: /*Program of sorting using radix sort*/ # include<stdio. tmp->info=item.i+1). &n).up).up). quick(arr. main() { struct node *tmp.arr[left]=temp.low. getch(). q->link=tmp. /* Inserting elements in the linked list */ tmp= malloc(sizeof(struct node)).h> struct { node int info . else { q=start. while(q->link!=NULL) q=q->link. if(start==NULL) /* Inserting first element */ start=tmp.n.i++) printf("%d ". printf("Enter the number of elements in the list : ").

display(). i++) { rear[i] = NULL. printf("Sorted list is :\n"). p = start . while( p != NULL) { /*Find kth digit in the number*/ dig = digit(p->info. p->info). i <= 9 . for(i=mindig.least_sig.k. rear[dig] = p .dig.mindig. front[i] = NULL . /*Join all the queues to form the new linked list*/ start=front[mindig]. radix_sort(). if(dig>maxdig) maxdig=dig.i++) ". } printf("\n").most_sig. }/*End of display()*/ radix_sort() { int i. mindig=9. struct node *p.k). p= p->link. else rear[dig]->link = p . }/*End of main()*/ display() { struct node *p=start. k <= most_sig .maxdig).printf("Unsorted list is :\n").maxdig. k++) { printf("PASS %d : Examining %dth digit from right for(i = 0 . while( p !=NULL) { printf("%d ".k. least_sig=1. for(k = least_sig. display (). k)./*Go to next number in the list*/ }/*End while */ /* maxdig and mindig are the maximum amd minimum digits of the kth digits of all the numbers*/ printf("mindig=%d maxdig=%d\n". /*Add the number to queue of dig*/ if(front[dig] == NULL) front[dig] = p . .mindig. } maxdig=0. if(dig<mindig) mindig=dig. most_sig=large_dig(start). *rear[10]. p=p->link. *front[10].i<maxdig.

else rear[i+1]=rear[i]. } printf("Number of digits in it are %d\n". } /*End of large_dig()*/ /*This function returns kth digit of a number*/ int digit(int number. i++) { digit = number % 10 . } return(digit).i. } rear[maxdig]->link=NULL.h> #define MAX 20 void main() { int arr[MAX].temp. }/* End for */ }/*End of radix_sort*/ /* This function finds number of digits in the largest element of the list */ int large_dig() { struct node *p=start . printf("New list : "). i <=k . large = large/10 .ndig).ndig = 0 . } printf("Largest Element is %d . ". int large = 0. for(i = 1 . . }/*End of digit()*/ Program of sorting using selection sort Code: /*Program of sorting using selection sort*/ #include<stdio.{ if(rear[i+1]!=NULL) rear[i]->link=front[i+1]. clrscr(). p = p->link .large). return(ndig). while(large != 0) { ndig++. while(p != NULL) { if(p ->info > large) large = p->info. number = number /10 .n.smallest. i .h> #include<conio. printf("Enter the number of elements : ").k. display().j. int k) { int digit.

i+1). arr[i]).n. j < n. } if(i!=smallest) { temp=arr[i]. scanf("%d". /*Selection sort*/ for(i=0. scanf("%d".i+1). }/*End of for*/ printf("Sorted list is : \n").i++) { /*Find the smallest element*/ smallest = i. i++) printf("%d ". scanf("%d". for (i = 0.&arr[i]). arr[smallest] = temp . for (i = 0. getch().&n). }/*End of main()*/ Program of sorting using shell sort ".&n). k < n .j. printf("\nEnter maximum increment (odd value) : "). arr[i]). i. printf("\n").k.scanf("%d". arr[i]=arr[smallest]. for(k = i + 1.i+1). i < n. i < n. i < n. j++) printf("%d ". printf("\n"). k++) { if(arr[smallest] > arr[k]) smallest = k . printf("Enter the number of elements : "). .i++) { printf("Enter element %d : ". } printf("Unsorted list is : \n"). arr[i]).h> #define MAX 20 main() { int arr[MAX]. i++) printf("%d ". printf("\n").i<n-1.incr. for (i = 0. for (i = 0. i < n.i<n. &arr[i]). arr[j]). i++) printf("%d ". i++) { printf("Enter element %d : ". } printf("Unsorted list is :\n"). for(i=0. } printf("After Pass %d elements are : for (j = 0. Code: /* Program of sorting using shell sort */ #include <stdio.

for (i = 0. printf("\n"). arr[i+incr]=k. i++) printf("%d ". i < n.C */ # include<stdio. void display(int *. ++k) { i = k . i >= 0 && k < arr[i]. i. int). }/*End of main()*/ Heap Sort Code: /* HEAP SORT */ /* HEAP. } printf("Increment=%d \n".h> void heap_sort(int *.incr).&incr). while((i > 1) && (temp > list[j])) { list[i] = list[j]. i = i-incr) arr[i+incr]=arr[i]. i = j . /*Decrease the increment*/ }/*End of while*/ printf("Sorted list is :\n"). for(i = j-incr. for (i = 0. j. arr[i]). arr[i]). temp = list[k]. } } . i++) printf("%d ". /*Shell sort*/ while(incr>=1) { for(j=incr. j = i / 2 . /* Definition of the function */ void create_heap(int list[].j++) { k=arr[j]. j = i / 2 . k <= n.scanf("%d". int ). temp. for(k = 2 . incr=incr-2. } list[i] = temp . printf("\n"). int). void create_heap(int *. int n ) { int k. if ( j < 1 ) j = 1 .j<n. i < n.

--k) { temp = list[1] . } } /* Function main */ void main() { int list[100]. int step = 1. } /* end of while statement */ printf("\n Step = %d ". step++. list[p]). for(k = n . p++) printf(" %d". int n) { int k. list[k] = temp . for(p = 1. k >= 2. size). int i. value./* End of heap creation function */ /* Definition of the function */ void heap_sort(int list[]. value = list[1]. j. while((j <= ( k-1)) && (list[j] > value)) { list[i] = list[j]. if((j+1) < k) if(list[j+1] > list[j]) j ++. i = 1 . printf("\n Size of the list: %d". . temp. for(i = 1 . else if( j > n) j = n . list[1] = list[k]. i. step). j = 2 . p. j = 2*i . list[i]). list[i] = value. size = 13 . p <= n. int n) { int i. i = j . } /* end for loop */ } /* Display function */ void display(int list[]. i <= n. if((j+1) < k) if(list[j+1] > list[j]) j++. ++ i) { printf(" %d".

++i) { list[i] = rand() % 100. } OUTPUT: Size of the list: 13 Entered list is as follows: 41 67 34 0 69 24 78 58 Heap 81 67 78 62 64 69 34 0 62 58 64 41 5 5 45 24 81 45 Step Step Step Step Step Step Step Step Step Step Step Step = = = = = = = = = = = = 1 2 3 4 5 6 7 8 9 10 11 12 78 67 69 62 64 45 34 0 58 41 5 24 81 69 67 45 62 64 24 34 0 58 41 5 78 81 67 64 45 62 41 24 34 0 58 5 69 78 81 64 62 45 58 41 24 34 0 5 67 69 78 81 62 58 45 5 41 24 34 0 64 67 69 78 81 58 41 45 5 0 24 34 62 64 67 69 78 81 45 41 34 5 0 24 58 62 64 67 69 78 81 41 24 34 5 0 45 58 62 64 67 69 78 81 34 24 0 5 41 45 58 62 64 67 69 78 81 24 5 0 34 41 45 58 62 64 67 69 78 81 5 0 24 34 41 45 58 62 64 67 69 78 81 0 5 24 34 41 45 58 62 64 67 69 78 81 Sorted list is as follows : 0 5 24 34 41 45 58 62 64 67 Press any key to continue 69 78 81 Bubble Sort Code: /* bubble. size). i <= size . display(list. printf("\n\n"). size).h> void bubble_sort(int array[]. size). printf("\n Heap\n").size). heap_sort(list. display(list.h> #include <stdlib. printf("\n\n Sorted list is as follows :\n\n").c */ #include <stdio. int size) { . display(list.size). } printf("\n Entered list is as follows:\n").for(i = 1 . create_heap(list.

printf(" %d". values[i]). rand()%100). printf("\n Sorted list is as follows\n"). j++) if (array[i] < array[j]) { temp = array[i]. k. void display(int*. temp. 10). void insertion_sort(int l[]. temp = l[i]. array[j] = temp. i. i. i <= n. i < size. int).C */ # include<stdio. int i.h> # include<stdlib.h> void insertion_sort(int *. for (i = 0. array[i] = array[j]. int). i++) { pointer = i -1. while(temp < l[pointer]) . for (i = 0. l[0] = -0. i++) { values[i] = rand() % 100. i < 10. for (i = 0. j < size.int temp. } } void main(void) { int values[30]. printf("\n Unsorted list is as follows\n"). for(i = 1 . i < 10. } bubble_sort(values. } OUTPUT: Unsorted list is as follows 67 0 24 58 64 45 27 91 42 36 Sorted list is as follows 27 34 41 61 62 69 78 81 95 Press any key to continue Insertion Sort Code: /* Insertion sort */ /* INSERT. i++) for (j = 0. int n) { int pointer. j. i++) printf("%d ".

int n) { int i. l[k]). number). number). insertion_sort(list. k <= n. i++) printf(" %d". l[i]). } } void display(int l[]. for(i = 1. int i. printf("Step = %d". i <= n. i <= number. printf("\n Sorted list is as follows\n"). i++) { list[i] = rand() %100. printf("\n Unsorted list is as follows \n"). rand() %100). for(i = 1. printf("\n Number of elements in the list: %i". } printf("\n"). i). } OUTPUT: Number of elements in the list: 10 Unsorted list is as follows 67 0 24 58 64 45 27 91 42 36 Step wise result is as follows Step Step Step Step Step Step Step Step Step = = = = = = = = = 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 41 34 69 78 62 5 34 41 69 78 62 5 34 41 69 78 62 5 34 41 69 78 62 5 34 41 62 69 78 5 5 34 41 62 69 78 5 34 41 62 69 78 5 34 41 61 62 69 5 34 41 61 62 69 81 81 81 81 81 81 81 78 78 61 61 61 61 61 61 61 81 81 95 95 95 95 95 95 95 95 95 27 27 27 27 27 27 27 27 27 . int list[100]. pointer --. display(list.{ l[pointer+1] = l[pointer]. k++) printf(" %d". printf(" %d". for(k = 0.number). } l[pointer+1] = temp. } void main() { int number = 10. printf("\n Step wise result is as follows \n\n"). printf("\n").

int s = size +1 . } if(f <=size) { for(f = f . int . int ). f++) { temp[t] = l[f]. int f = top. int ).h> # include<stdlib. while(( f <= size)&&(s <=bottom)) { if(l[f] <= l[s]) { temp[t] = l[f] . } t ++. } } . int . } else { temp[t] = l[s] . t++. int top. s<= bottom . int bottom) { float temp[1000]. void merge_pass(float *. s++) { temp[t]=l[s]. } } else { for(s = s .c */ # include<stdio. int size. /* Definition of the function */ void merge_sort(float l[]. int upper. int .h> void merge_sort(float *. f ++. f<=size. s ++. int t = top .Step = 10 0 5 27 34 41 61 62 69 78 81 95 Sorted list is as follows 5 27 34 41 61 62 69 78 81 95Press any key to continue Merge Sort Code: /* MERGE SORT */ /* merge. t++.

} } /* main function */ void main() { float list[1000]. n ). } OUTPUT: Size of the list: 30 Entered list as follows: 41 67 34 0 69 24 78 58 62 64 5 45 81 27 61 91 95 42 27 36 9 1 4 2 53 92 82 21 16 18 95 Merge sorted list is as follows: 0 2 4 5 16 18 21 24 27 27 34 36 41 42 45 53 58 61 62 64 67 69 78 81 82 91 91 92 95 95 . merge_pass(list. merge_pass( append. upper <= bottom . i++) { list[i] = (float) (rand() %100). mid+1. mid ). n). int n ) { if( m!= n) { int mid = (m+n)/2. merge_sort( append. (int) list[i]). } } /* Definition of the function */ void merge_pass( float append[]. i < n . i<n . upper++) { l[upper]=temp[upper]. int m. i++) printf(" %d". for( i = 0 . printf("\n Merge sorted list is as follows:\n").for(upper = top. int i. merge_pass( append. i++) printf(" %d ". n ). for(i = 0 . for( i = 0 . i = 0 . i<n . mid. } printf("\n Entered list as follows:\n"). (int) list[i]). m. m. i. n-1). n = 30. printf("\n Size of the list: %d".

case 2: printf("Enter String:."). int i.&c).b[25].Concate two string\n4.c.a). #include<conio.l. .pos. printf("Enter Your choice \n1.Press any key to continue 1.Find Lenght of String\n2. clrscr().a)."). scanf("%s". i=0.i). while(a[i]!='\0') i++. //counts no of chars till encountering null char printf("string length=%d". switch(c) { case 1: printf("Enter String:. scanf("%d".h> #include<stdio.j[100]. break.k.Copy One string to other\n3.h> void main() { char a[25].Find substring \n\n Your Choice:-"). scanf("%s".

++i. while(a[i]) { j[i]=a[i]. printf("Copied Stringb = %s". .b[i]!='\0'.a). b[i]='\0'.i++) b[i]=a[i]. while(b[l]) { j[i]=b[l]. ++l. i=0.b). scanf("%s".for(i=0. } j[i]=' '. ++i.l=0. scanf("%s".b). ++i."). printf("\nEnter second String:. case 3: printf("Enter first String:. break."). } j[i]='\0'.

printf("Enter Positon and lenght of string: "). getch(). } c=i-pos+1.i++).a[i]!='\0'. if(pos>i) { printf("Invalid Position!!"). printf(j). getch(). for(i=0. scanf("%d%d".&l). for(k=0.k++) . exit (0). exit (0). break.&pos. case 4: printf("Enter Sting= "). scanf("%s". } c=0.a).printf("\nconcated string= "). c=pos-1.k<l. if(l>c) { printf("Invalid SubString").

break. } .{ j[k]=a[c]. } j[k]='\0'. } getch(). case 5: break. c++.j). printf("substring= %s". default: printf("Invalid Selection"). break.