NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

//Bubble sort
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr[]={10,9,8,7,6,5,4 ,3 ,2,1};
int i,j,size=10;
for(i =0;i<size;i++){
for(j=0;j<size;j++){
if(arr[j]>arr[j+1]){
swap(arr[j],arr[j+1]);
}
}
}

for(int i=0;i<size;i++){
cout << arr[i]<< " ";
}
return 0;
}
//end bubble sort

///start Selection Sort
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr[]={7,6,5,4,3,2,1};
int i,j,min_index;
for(i=0;i<7;i++){
min_index=i;
for(j=i+1;j<7;j++){
if(arr[j]<arr[min_index]){
min_index = j;
}
}
swap(arr[i],arr[min_index]);
}
cout << "After use selection sort"<<endl;
for(int i=0;i<7;i++){
cout << arr[i]<< " ";
}
return 0;
}
///End SelectionSort

/// Start quick sort
#include<bits/stdc++.h>
using namespace std;

int partition_array(int arr[],int start,int en){
int pivot = arr[en];
int partitionIndex = start;
for(int i=start;i<en;i++){
if(arr[i]<= pivot){
swap(arr[i],arr[partitionIndex]);
partitionIndex++;
}
}
swap(arr[partitionIndex],arr[en]);
return partitionIndex;
}
void quicksort(int arr[],int start,int en){
if(start< en){
int partitionIndex = partition_array(arr,start,en);
quicksort(arr,start,partitionIndex-1);
quicksort(arr,partitionIndex+1,en);
}

}
int main(){
int arr[100],n;
cin>> n;
for(int i=0;i<n;i++){
cin >> arr[i];
}
quicksort(arr,0,n-1);
cout<< "After use quick sort"<<endl;
for(int i=0;i<n;i++){
cout<< arr[i]<<" ";
}
cout <<endl;
return 0;
}
///End quic sort

///start binary search
#include<stdio.h>
int main(){
int arr[]= {2,3,4,6,8,10,11};

int left=0,right=6;
int middle,item = 8;
while(left <= right){
middle = (left+right)/2;
if(arr[middle] == item){
printf("Item founded index %dn",middle);
return 0;
}else if( arr[middle] < item){
left = middle + 1;
}else {
right = middle - 1;
}
}
printf("Not founded this itemn");
return 0;
}
///end binary search

///start stack
#include<stdio.h>
#define capacity 3
int top = -1;
int stack[capacity];
///here are push function we call
void push(int x){
if(top < capacity - 1){
top = top + 1;
stack[top]= x;
printf("Successfully added this item %dn",x);
}else{
printf("Execcption from no spacen");
}
}
///Here are pop function we call
void pop(){
if(top >= 0){
int val = stack[top];
top = top -1;
return val;
}else{
printf("EXecception from no spacen");
return -1;
}
}

///Here are peek function we call
int peek(){
if(top >= 0){
return stack[top];
}else{
printf("EXceeption from peek,empty peek n");
return -1;
}

}
int main(){
push(10);
push(20);
push(30);
pop();
push(40);
printf("peek item %dn",peek());
return 0;
}
///end stack
///start dfs
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int dist[1000],visit[1000];

vector<int>vv[1000];

void dfs(int src){
visit[src] = 1;
for(int i = 0; i<vv[src].size();i++){
int node = vv[src] [i];
if(visit[node] == 0){
dist[node] = dist[src] + 1;
dfs(node);
}
}

}
int main(){
int node,edge;
printf("How many nodes and edgesn");
scanf("%d %d",&node,&edge);
printf("Enter nodes from and ton");
for(int i=0;i<edge;i++){
int from, to;
scanf("%d %d",&from,&to);
vv[from].push_back(to);
vv[to].push_back(from);
}
printf("Enter source and targetn");
int src,tar;
scanf("%d %d",&src,&tar);
dfs(src);
printf("%dn",dist[tar]);
}

///end dfs


     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.