GithubHelp home page GithubHelp logo

data-structures-array's Introduction

Data-Structures-Array

Summary: In this program, I developed different void functions to reconfigure or merge the data given by the elements of the array.

Method: For questions 1-3 and 5, I created 2 void functions that gives random values to the array by using srand() from the #ctime and #cstdlib libraries. For question 4, I placed the array inside of int main() because this method allowed me to merge 2 arrays with less difficulty. Note that each question contains an additional and unique void or int function that is referenced in the int main().

Questions Answered:

  1. Write a C++ function rotate(int arr[], int d, int n) that rotates arr[] of size n to the left by d elements.

  2. Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), write a C++ function maxProfit(int prices[], int size) to find the maximum profit.

  3. Given an array of random numbers, write a C++ function pushZerosToEnd(int arr[], int n) to push all the zero’s of a given array to the end of the array.

  4. Given two sorted arrays, write a C++ function mergeArrays(int arr1[], int arr2[], int n1, int n2, int arr3[]) to merge them in a sorted manner.

  5. Given an array of size n, write a C++ function findMajority(int arr[], int size) to find the majority element. The majority element is the element that appears more than ⌊ n/2⌋ times. You may assume that the array is non-empty and the majority element always exist in the array.

data-structures-array's People

Contributors

vidhurva avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.