Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
16 views
2 pages
DS Part 2
Uploaded by
mahammadsuhail12345
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download
Save
Save DS PART 2 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
16 views
2 pages
DS Part 2
Uploaded by
mahammadsuhail12345
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save DS PART 2 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save DS PART 2 For Later
You are on page 1
/ 2
Search
Fullscreen
Queue using Quick sort stack using linked
Merge sort array technique list
1]#include<stdio.h> 2]#include<stdio.h> printf("elements in queue i=first; int choice=0;
void merge_sort(int i,int #define max 6 are\n"); j=last; clrscr();
j,int a[],int aux[]){
int queue[max]; while(i<=rear){ while(i<j){ while(choice!=4){
int mid,leftp,rightp,k;
if(j<=i){ int front=-1; printf("%d\n",queue[i]); while(a[i]<=a[ptr]&&i<last) printf("\n\n choose one from the
return;} int rear=-1; i=(i+1)%max;}}} i++; below option...\n");
mid=(i+j)/2; void enqueue(int element) int main(){ while(a[j]>a[ptr]) printf("\n1.Push\n2.Pop\n3.Sho
merge_sort(i,mid,a,aux); { int ch,x; j--; w\
merge_sort(mid+1,j,a,aux if(front==-1&rear==-1){ clrscr(); if(i<j){ n4.Exit");
);
front=0; while(1){ temp=a[i]; printf("\n Enter your choice:");
leftp=i;
rightp=mid+1; rear=0; printf("\n1.insert"); a[i]=a[j]; scanf("%d",&choice);
for(k=i;k<=j;k++){ queue[rear]=element;} printf("\n2.delete"); a[j]=temp;}} switch(choice){
if(leftp==mid+1){ else printf("\n3.display"); temp=a[ptr]; case 1:push();
aux[k]=a[rightp]; if((rear+1)%max==front){ printf("\n4.exit"); a[ptr]=a[j]; break;
rightp++;} printf("queue is full\n");} printf("\nenter your a[j]=temp; case 2:pop();
else if(rightp==j+1){
else{ choice:"); quicksort(a,first,j-1); break;
aux[k]=a[leftp];
leftp++;} rear=(rear+1)%max; scanf("%d",&ch); quicksort(a,j+1,last);}} case 3:display();
else if(a[leftp]<a[rightp]){ queue[rear]=element;}} switch(ch){ void main(){ break;
aux[k]=a[leftp]; void dequeue(){ case 1:printf("enter int i,n,a[25]; case 4:break;
leftp++;} if((front==-1)&&(rear==- elements to be inserted:"); clrscr(); default:printf("Please enter a
else{ 1)){ scanf("%d",&x); printf("Enter the size of the valid choice");}}}
aux[k]=a[rightp];
printf("queue is enqueue(x); array:"); void push(){
rightp++;}}
for(k=i;k<=j;k++){ empty\n"); break; scanf("%d",&n); int val;
a[k]=aux[k];}} } case 2:dequeue(); printf("Enter %d struct node*ptr=(struct
int main(){ else if(front==rear){ break; elements:",n); node*)malloc(sizeof(struct
int printf("element %d is case 3:display(); for(i=0;i<n;i++) node));
a[100],aux[100],n,i,d,swa dequeued\n",queue[front]) break; scanf("%d",&a[i]); if(ptr==NULL){
p;
; case 4:exit(0);}}} quicksort(a,0,n-1); printf("Unable to push the
clrscr();
printf("Enter number of front=-1;rear=-1;} printf("Order of Sorted elemen
elements in the array:\n"); else{ elements:"); t");}
scanf("%d",&n); front=(front+1)%max; for(i=0;i<n;i++) else{
printf("Enter %d printf("element %d is printf("%d\n",a[i]); printf("Enter the value:");
integers:\n",n);
3]#include<stdio.h>
dequeued\n",queue[front- #include<conio.h> getch();} scanf("%d",&val);
for(i=0;i<n;i++)
1]);}} void quicksort(int a[25],int if(head==NULL){
scanf("%d",&a[i]); 4]#include<stdio.h>
merge_sort(0,n-1,a,aux); void display(){ first,int last){ #include<stdlib.h> ptr->val=val;
printf("Printing the sorted int i=front; int i,j,ptr,temp; void push(); ptr->next=NULL;
array:\n"); if(front==-1&&rear==- if(first<last){ void pop(); head=ptr;}
for(i=0;i<n;i++) 1){ void display(); else{
printf("%d\n",a[i]);
ptr=first; struct node{
printf("queue is ptr->val=val;
getch(); int val;
empty\n");} ptr->next=head;
return 0;} struct node*next;};
else{ struct node*head; head=ptr;}
void main(){ printf("Item pushed");}}
Queue using void pop(){
Postfix expression
linked list
int item; 5]#include<stdio.h> else{ 6]#include<stdio.h> switch(c) {
struct node*ptr; #include<stdlib.h> printf("\nenter a value:\n") ; #include<conio.h> case'+':ans=b+a;
if(head==NULL){ struct node{ scanf("%d",&item); #include<string.h> break;
printf("Underflow");} int data; ptr->data=item; #define MAX 50 case'-':ans=b-a;
else{ struct node*next;}; if(front==NULL){ int stack[MAX]; break;
item=head->val; struct node*front; front=ptr; char post[MAX]; case'*':ans=b*a;
ptr=head; struct node*rear; rear=ptr; int top=-1; break;
head=head->next; void insert(); front->next=NULL; void pushstack(int temp); case'/':ans=b/a;
free(ptr); void del(); rear->next=NULL;} void evaluate(char c); break;
printf("Item %d void display(); else{ void main(){ case'^':ans=b^a;
popped",item) void main(){ rear->next=ptr; int i,l; break;
;}} int ch; rear=ptr; clrscr(); default:ans=0;
void display(){ clrscr(); rear->next=NULL;}}} printf("Insert a postfix }
int i; while(1){ void del(){ notation top++;
struct node*ptr; printf("\n1.insert an struct node*ptr; n:"); stack[top]=ans; }
ptr=head; element\n2.delete an if(front==NULL){ gets(post);
if(ptr==NULL){ element\n3.display the printf("\nUNDERFLOW\n" l=strlen(post);
printf("Stack is queue\n4.exit\n"); ); for(i=0;i<l;i++){
empty\n");} printf("\nenter your return;} if(post[i]>='0'&&post[i]<='9')
else{ choice:"); else{ {
printf("Printing Stack scanf("%d",&ch); ptr=front; pushstack(i);}
elements switch(ch){ printf("\n%d is if(post[i]=='+'||post[i]=='-
\n"); case1:insert(); deleted\n",ptr->data); '||post[i]=='*'||post[i]=='/'||post
while(ptr!=NULL){ break; front=front->next; [i
printf("%d\n",ptr- case2:del(); free(ptr);}} ]=='^'){
>val); break; void display(){ evaluate(post[i]);}}
ptr=ptr->next;}}} case3:display(); struct node*ptr; printf("\n\nResult::%d",stack[t
break; ptr=front; o
case4:exit(0); if(front==NULL){ p]);
break; printf("\nempty queue\n");} getch();}
default:printf("\nenter a else{ void pushstack(int temp){
valid choice:");}}} while(ptr!=NULL){ top++;
void insert(){ printf("\n%d\n",ptr->data); stack[top]=(int)(post[temp]-
struct node*ptr; ptr=ptr->next;}}} 48);}
int item; void evaluate(char c){
ptr=(struct int a,b,ans;
node*)malloc(sizeof(struc a=stack[top];
t node)); stack[top]='\0';
if(ptr==NULL){ top--;
printf("\nOVERFLOW\n" b=stack[top];
); stack[top]='\0';
return;} top--;
Queue using Quick sort stack using linked
Merge sort array technique list
7]#include <stdio.h> 8]#include<stdio.h>
#include <stdlib.h> typedef struct tnode{
struct node{ int data; #include <stdlib.h>
int data; struct tnode *right, *left;
struct node*next;}; } TNODE;
struct node*head; TNODE *CreateBST(TNODE *, int);
void beginsert(); void Inorder(TNODE *);
void random_delete(); void Preorder(TNODE *);
void display(); void Postorder(TNODE *);
void main(){ void main(){
int ch; TNODE *root = NULL;
while(1){ int choice=0, elem, n, i;
printf("\n\n******Main Menu*******\n"); clrscr();
printf("\n.Insert in beginning\n2.Delete a given while(choice<=2){
node\n3.Display\n4.Exit\n"); printf("\n\n Binary Search Tree Operations \n");
printf("\nEnter your choice:"); printf("\n 1.Creation of BST");
scanf("\n%d",&ch); printf("\n 2.Inorder, Preorder and Postorder Traversal");
switch(ch){ printf("\n 3.Exit");
case 1: printf("\n Enter Your choice: ");
beginsert(); scanf("%d", &choice);
break; switch (choice){
case 2: case 1:root = NULL;
random_delete(); printf("\n\nTotal number of nodes in BST :");
break; scanf("%d", &n);
case 3: for (i=1;i<=n;i++) {
display(); printf("\nEnter the element %d:", i);
break; scanf("%d", &elem);
case 4: root = CreateBST(root, elem);}
exit(0); printf("\nBST with %d nodes created\n", n);
default: break;
printf("Please enter valid choice..");}}} case 2: printf("\n Inorder Traversal:");
void beginsert(){ Inorder(root);
struct node*ptr; printf("\n Preorder Traversal: ");
int item; Queue using Preorder(root);
ptr=(struct node*)malloc(sizeof(struct node*)); printf("\n Postorder Traversal:"); Postfix expression
if(ptr==NULL){
linked list
(sizeof(structnode*)); Postorder(root);
printf("nOVERFLOW");} break;}}
else{ getch();}
printf("\nEnter value\n"); TNODE *CreateBST(TNODE *root, int elem){
scanf("%d",&item); if (root == NULL){
ptr->data=item; root = (TNODE *) malloc(sizeof(TNODE));
ptr->next=head; root->left = root->right = NULL;
head=ptr; root->data = elem;
printf("\n%d inserted",item);}} return root;}
void random_delete(){ else if (elem < root->data)
struct node*temp; root->left = CreateBST(root->left, elem);
struct node*del; else
int loc,i; root->right = CreateBST(root->right, elem);
printf("\nEnter the position to delete the node:\n"); return (root);}
scanf("%d",&loc); void Inorder(TNODE *root){
temp=head; if (root != NULL){
if(loc==0){ Inorder(root->left);
printf("\nElement deleted is %d\n",temp->data); printf(" %d ", root->data);
head=head->next; Inorder(root->right);}}
temp->next==NULL; void Preorder(TNODE *root){
free(temp);} if (root!= NULL){
else { printf(" %d ", root->data);
for(i=0;i<loc-1;i++){ Preorder(root->left);
temp=temp->next;} Preorder(root->right);}}
del=temp->next; void Postorder(TNODE *root){
temp->next=temp->next->next; if (root != NULL){
printf("\nElement deleted is:%d\n",del->data); Postorder(root->left);
del->next=NULL; Postorder(root->right);
free(del);}} printf(" %d ", root->data);}}
void display(){
struct node*ptr;
ptr=head;
if(ptr==NULL){
printf("No element found!\n");}
else{
printf("Elements are:\n");
while(ptr!=NULL){
printf("%d",ptr->data);
ptr=ptr->next;}}}
You might also like
UiPath Cheat Sheet
PDF
100% (4)
UiPath Cheat Sheet
3 pages
Importing SEG-Y Data With Variable Delay Header Into Kingdom 8.7
PDF
No ratings yet
Importing SEG-Y Data With Variable Delay Header Into Kingdom 8.7
6 pages
Krishg DS
PDF
No ratings yet
Krishg DS
9 pages
Dsa Lab Manual
PDF
No ratings yet
Dsa Lab Manual
35 pages
Vanshika Ds Lab-File
PDF
No ratings yet
Vanshika Ds Lab-File
27 pages
Data Structure1
PDF
No ratings yet
Data Structure1
14 pages
IC 309-Programming III Data Structures and Algorithms: Submitted By: Hitesh Bahl 450/IC/09
PDF
No ratings yet
IC 309-Programming III Data Structures and Algorithms: Submitted By: Hitesh Bahl 450/IC/09
29 pages
Niteshprajapati
PDF
No ratings yet
Niteshprajapati
22 pages
Ds Fair - Final (6) 4
PDF
No ratings yet
Ds Fair - Final (6) 4
38 pages
Circularqueue Merged
PDF
No ratings yet
Circularqueue Merged
35 pages
DS Progam
PDF
No ratings yet
DS Progam
60 pages
Dsa File
PDF
No ratings yet
Dsa File
43 pages
Cs3311-To Print
PDF
No ratings yet
Cs3311-To Print
59 pages
Linkkist
PDF
No ratings yet
Linkkist
29 pages
Array Queue
PDF
No ratings yet
Array Queue
39 pages
#Include #Include
PDF
No ratings yet
#Include #Include
23 pages
Ds 1
PDF
No ratings yet
Ds 1
76 pages
DS 24-25 Print
PDF
No ratings yet
DS 24-25 Print
70 pages
Prathmesh
PDF
No ratings yet
Prathmesh
2 pages
Data Structure
PDF
No ratings yet
Data Structure
86 pages
Ds Lab Manual Part B 2025
PDF
No ratings yet
Ds Lab Manual Part B 2025
15 pages
Practical 8 To 12
PDF
No ratings yet
Practical 8 To 12
16 pages
Dsaa
PDF
No ratings yet
Dsaa
49 pages
Dsa Lab
PDF
No ratings yet
Dsa Lab
19 pages
DAS Lab Programs2024
PDF
No ratings yet
DAS Lab Programs2024
55 pages
Data Sturcture and Algorithm Lab Manual
PDF
No ratings yet
Data Sturcture and Algorithm Lab Manual
61 pages
DST External Program
PDF
No ratings yet
DST External Program
21 pages
DS Final Record WORD
PDF
No ratings yet
DS Final Record WORD
87 pages
2nd Sem Final PDF
PDF
No ratings yet
2nd Sem Final PDF
25 pages
Dsa Program
PDF
No ratings yet
Dsa Program
85 pages
Implementation of Stack
PDF
No ratings yet
Implementation of Stack
20 pages
Ads File
PDF
No ratings yet
Ads File
65 pages
Practical Assignment
PDF
No ratings yet
Practical Assignment
42 pages
Shivank Practicals
PDF
No ratings yet
Shivank Practicals
31 pages
DSA Practical Codes - 122436
PDF
No ratings yet
DSA Practical Codes - 122436
16 pages
Ds Practical Qs
PDF
No ratings yet
Ds Practical Qs
23 pages
DS LAB Programs
PDF
No ratings yet
DS LAB Programs
32 pages
Practical 1 Dsa
PDF
No ratings yet
Practical 1 Dsa
19 pages
23UDSSBP301 DS - Lab
PDF
No ratings yet
23UDSSBP301 DS - Lab
26 pages
Lab Manual MCA DSC (Practical 1-11)
PDF
No ratings yet
Lab Manual MCA DSC (Practical 1-11)
27 pages
DSA Lab
PDF
No ratings yet
DSA Lab
20 pages
Data Structure Management
PDF
No ratings yet
Data Structure Management
47 pages
Practical Fil1 (Ankush Shukla 206320040)
PDF
No ratings yet
Practical Fil1 (Ankush Shukla 206320040)
32 pages
Docfile
PDF
No ratings yet
Docfile
44 pages
Lab Cycle
PDF
No ratings yet
Lab Cycle
82 pages
Data Structure Lab Manual
PDF
No ratings yet
Data Structure Lab Manual
24 pages
Program Using Function of Array
PDF
No ratings yet
Program Using Function of Array
60 pages
Data Structure
PDF
No ratings yet
Data Structure
21 pages
Ques
PDF
No ratings yet
Ques
78 pages
Data ST
PDF
No ratings yet
Data ST
109 pages
Chrisfred Assignment
PDF
No ratings yet
Chrisfred Assignment
7 pages
DSA Lab Internal III Programs
PDF
No ratings yet
DSA Lab Internal III Programs
12 pages
Data Structure-1
PDF
No ratings yet
Data Structure-1
76 pages
Cprogs
PDF
No ratings yet
Cprogs
34 pages
DSA List of Experiments
PDF
No ratings yet
DSA List of Experiments
62 pages
Programs
PDF
No ratings yet
Programs
21 pages
Data Structure Lab Manual
PDF
No ratings yet
Data Structure Lab Manual
91 pages
Dsa PDF
PDF
No ratings yet
Dsa PDF
28 pages
Data C Programming
PDF
No ratings yet
Data C Programming
8 pages
Lab Assignment - V (Bcac393)
PDF
No ratings yet
Lab Assignment - V (Bcac393)
26 pages
DS 5 To 15
PDF
No ratings yet
DS 5 To 15
29 pages
Inter-Process Communication - Wikipedia, The Free Encyclopedia
PDF
No ratings yet
Inter-Process Communication - Wikipedia, The Free Encyclopedia
4 pages
PL/SQL - Constants and Literals
PDF
No ratings yet
PL/SQL - Constants and Literals
4 pages
Launcher Log
PDF
No ratings yet
Launcher Log
177 pages
Feedback - Quiz 1: You Submitted This Quiz On Sat 30 Jan 2016 10:32 PM PET. You Got A Score of 100.00 Out of 100.00
PDF
No ratings yet
Feedback - Quiz 1: You Submitted This Quiz On Sat 30 Jan 2016 10:32 PM PET. You Got A Score of 100.00 Out of 100.00
9 pages
Thesis For Computer Science
PDF
100% (1)
Thesis For Computer Science
5 pages
Welcome To... : The Web Developer Bootcamp
PDF
No ratings yet
Welcome To... : The Web Developer Bootcamp
30 pages
5 Best Antivirus Software: 3. Malwarebytes Anti-Malware
PDF
No ratings yet
5 Best Antivirus Software: 3. Malwarebytes Anti-Malware
3 pages
Cs8083 Unit V Notes
PDF
No ratings yet
Cs8083 Unit V Notes
24 pages
Computer Games Software Engineering
PDF
No ratings yet
Computer Games Software Engineering
304 pages
DBMS Lab Manual Editing New
PDF
No ratings yet
DBMS Lab Manual Editing New
44 pages
FEMAP Symposium 2013 - Advanced Post With Femap Api PDF
PDF
No ratings yet
FEMAP Symposium 2013 - Advanced Post With Femap Api PDF
78 pages
Omni - Arm Final 2 4
PDF
No ratings yet
Omni - Arm Final 2 4
25 pages
3 Stack
PDF
No ratings yet
3 Stack
17 pages
Assignment Cse 251 T
PDF
No ratings yet
Assignment Cse 251 T
33 pages
Git Best Practises
PDF
No ratings yet
Git Best Practises
14 pages
Mastering Apache Spark PDF
PDF
50% (2)
Mastering Apache Spark PDF
1,352 pages
PL SQL Collections
PDF
No ratings yet
PL SQL Collections
46 pages
Mic Question Bank
PDF
No ratings yet
Mic Question Bank
2 pages
Log
PDF
No ratings yet
Log
2 pages
Graph Theory For Dummies
PDF
No ratings yet
Graph Theory For Dummies
30 pages
SAP HANA 2.0: Deprecations Reported by The HANA Statistics Server
PDF
No ratings yet
SAP HANA 2.0: Deprecations Reported by The HANA Statistics Server
3 pages
Introduction To Java Understanding The Basics of Java Programming
PDF
No ratings yet
Introduction To Java Understanding The Basics of Java Programming
17 pages
SCL
PDF
No ratings yet
SCL
10 pages
Power BI Week 2
PDF
No ratings yet
Power BI Week 2
43 pages
Rivan CV
PDF
No ratings yet
Rivan CV
1 page
Unit - Iv RDBMS Notes
PDF
No ratings yet
Unit - Iv RDBMS Notes
22 pages
Operating Systems Lab Experiment 3 CPU Scheduling Algorithms
PDF
No ratings yet
Operating Systems Lab Experiment 3 CPU Scheduling Algorithms
30 pages
Agile Visualization
PDF
No ratings yet
Agile Visualization
235 pages