Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Problem Solving/bubble.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<iostream>
using namespace std;
int main(){
int arr[10] = {5,4,3,2,1};
int n = 5;
for(int i=0;i<n;i++){
for(int j=0;j<n-1-i;j++){
if(arr[j]>arr[j+1]){
//swap
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cin>>n;
}
62 changes: 62 additions & 0 deletions Problem Solving/stack_ll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include<iostream>
using namespace std;
template<typename T>
struct node{
T data;
node * next;

node(T data){
this->data = data;
this->next = NULL;
}
};
template<typename T>
struct stack{
private:
node<T> * head;
int size;
public:
stack(){
head = NULL;
size = 0;
}
bool isEmpty(){
return head==NULL;
}
int Size(){
return size;
}
void push(T data){
node<T> * temp = new node<T>(data);
temp->next = head;
head = temp;
size++;
return;
}
void pop(){
if(!isEmpty()){
node<T> * temp = head;
head = head->next;
delete temp;
size--;
}
return;
}
T top(){
if(!isEmpty()){
return head->data;
}
return NULL;
}
};
int main(){

stack<int> s;
cout<<s.Size()<<endl;
s.push(1);
s.push(2);
s.push(3);
cout<<s.top()<<endl;
s.pop();
cout<<s.top()<<endl;
}
23 changes: 23 additions & 0 deletions selection sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
using namespace std;
int main(){
int arr[10] = {5,4,3,2,1};
int n = 5;
for(int i=0;i<n;i++){
int min = INT_MAX;
int minIndex = i;
for(int j=i;j<n;j++){
if(arr[j]<min){
min = arr[j];
minIndex = j;
}
}
int temp = arr[i];
arr[i] = min;
arr[minIndex] = temp;
}
for(int i=0;i<5;i++){
cout<<arr[i]<<" ";
}
cin>>n;
}