Commit 4988a4fa authored by KSHITIJ SINGHA's avatar KSHITIJ SINGHA

add API and data read

parents
File added
#include <iostream>
#include <vector>
#include "sorting.h"
using namespace std;
void bubbleSort(vector<int>& a);
void printVector(vector<int> a);
int main(int argc, char const *argv[])
{
vector<int> a;
int num = 0;
while (num != -1)
{
std::cin>>num;
if (num != -1)
//add elements to the vector container
a.push_back(num);
}
//printVector(a);
bubbleSort(a);
printVector(a);
}
void printVector(vector<int> a)
{
for (int i=0; i <a.size(); i++)
{
cout<<a[i]<<" ";
}
}
using namespace std;
#include <vector>
void bubbleSort(vector<int>& a)
{
bool swapp = true;
while(swapp){
swapp = false;
for (size_t i = 0; i < a.size()-1; i++) {
if (a[i]>a[i+1] ){
a[i] += a[i+1];
a[i+1] = a[i] - a[i+1];
a[i] -=a[i+1];
swapp = true;
}
}
}
// return a;
}
#include <stdio.h>
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
// A function to implement bubble sort
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)
// Last i elements are already in place
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
}
/* Function to print an array */
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);
printf("n");
}
// Driver program to test above functions
int main()
{
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr)/sizeof(arr[0]);
bubbleSort(arr, n);
printf("Sorted array: \n");
printArray(arr, n);
return 0;
}
using namespace std;
void bubbleSort(vector<int>& a);
void printVector(vector<int> a);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment