From 84df03e1864dbb1722496e1cb575e294f9ec93ca Mon Sep 17 00:00:00 2001 From: Aditya Srivastava <72396688+abdzitter@users.noreply.github.com> Date: Tue, 6 Oct 2020 16:03:05 +0530 Subject: [PATCH 1/2] Update CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6b203b7..2a2af35 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,3 +29,7 @@ ### Sagar Gurung - Github: https://github.com/SagarGi + +### Aditya Srivastava + +- Github: https://github.com/abdzitter From 90b7b62780a833c5239a5a9c004312086a151493 Mon Sep 17 00:00:00 2001 From: Aditya Srivastava <72396688+abdzitter@users.noreply.github.com> Date: Tue, 6 Oct 2020 16:04:12 +0530 Subject: [PATCH 2/2] Add files via upload --- Data Structure/LinkedList | 88 +++++++++++++++++++++++++++++++++++++++ Data Structure/QuickSort | 56 +++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 Data Structure/LinkedList create mode 100644 Data Structure/QuickSort diff --git a/Data Structure/LinkedList b/Data Structure/LinkedList new file mode 100644 index 0000000..82fe205 --- /dev/null +++ b/Data Structure/LinkedList @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char* readline(); + +// Complete the utopianTree function below. +int utopianTree(int n) +{ + int sum=1; + for(int i=1;i<=n;i++) + { + if(i%2==0) + { + sum=sum+1; + } + else + { + sum=sum*2; + } + } + return sum; +} + +int main() +{ + FILE* fptr = fopen(getenv("OUTPUT_PATH"), "w"); + + char* t_endptr; + char* t_str = readline(); + int t = strtol(t_str, &t_endptr, 10); + + if (t_endptr == t_str || *t_endptr != '\0') { exit(EXIT_FAILURE); } + + for (int t_itr = 0; t_itr < t; t_itr++) { + char* n_endptr; + char* n_str = readline(); + int n = strtol(n_str, &n_endptr, 10); + + if (n_endptr == n_str || *n_endptr != '\0') { exit(EXIT_FAILURE); } + + int result = utopianTree(n); + + fprintf(fptr, "%d\n", result); + } + + fclose(fptr); + + return 0; +} + +char* readline() { + size_t alloc_length = 1024; + size_t data_length = 0; + char* data = malloc(alloc_length); + + while (true) { + char* cursor = data + data_length; + char* line = fgets(cursor, alloc_length - data_length, stdin); + + if (!line) { break; } + + data_length += strlen(cursor); + + if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; } + + size_t new_length = alloc_length << 1; + data = realloc(data, new_length); + + if (!data) { break; } + + alloc_length = new_length; + } + + if (data[data_length - 1] == '\n') { + data[data_length - 1] = '\0'; + } + + data = realloc(data, data_length); + + return data; +} diff --git a/Data Structure/QuickSort b/Data Structure/QuickSort new file mode 100644 index 0000000..5014615 --- /dev/null +++ b/Data Structure/QuickSort @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +using namespace std; +void swap(int *a,int *b) +{ + int temp=*a; + *a=*b; + *b=temp; +} +int Partition(int a[],int low,int high) +{ + int i,j; + i=low; + int pivot=a[high]; + for(j=low;j> n; + int a[n]; + for(int i=0;i>a[i]; + } + Quicksort(a,0,n-1); + for(int i=0;i