Git Product home page Git Product logo

cpp-stl's Introduction

C++ Standard Template Library

The C++ STL (Standard Template Library) is a powerful set of C++ template classes to provide general-purpose classes and functions with templates that implement many popular and commonly used algorithms and data structures like vectors, lists, queues, stacks, de-queues, priority queues.

At the core of the C++ Standard Template Library are following three well-structured components:

  • Containers: Containers are used to manage collections of objects of a certain kind. There are several different types of containers like deque, list, vector, map etc.

  • Algorithms: Algorithms act on containers. They provide the means by which you will perform initialization, sorting, searching, and transforming of the contents of containers.

  • Iterators: Iterators are used to step through the elements of collections of objects. These collections may be containers or subsets of containers.

cpp-stl's People

Contributors

ankit152 avatar anuragc2001 avatar ap1809 avatar aquasin avatar debanjan-2002 avatar indranildgupta avatar nayan424 avatar raysourish avatar sahilrik avatar saptarshiweb avatar shubhamsharma6701 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cpp-stl's Issues

`Vector` insertion

Given an array arr[] of size N containing integers. The task is to insert elements of given array to vector and return that vector and print it.

Input:
N = 4
arr[] = 1 2 3 4

Output:
1 2 3 4

Sort and Reverse Vector

You are given a vector V of size n. You need to sort it and reverse it.

Input:
n = 5
V = 1 2 3 4 5

Output:
1 2 3 4 5
5 4 3 2 1

Reverse Array Using Stack

You are given an array arr[] of size N, the task is to reverse the array elements by using a stack.

Input: N = 5, arr[] = {1, 2, 3, 4, 5}
Output: 5 4 3 2 1

Deletion from deque

Given a deque of size N, we need to delete elements from its front end one-by-one depending upon the user's choice.

Input:

2 3 5 6 1

Output:

3 5 6 1
Do you wish to delete one more element(y/n)?y

5 6 1
Do you wish to delete one more element(y/n)?y

6 1
Do you wish to delete one more element(y/n)?n

Note - The program will also notify when the deque will become empty.

Find the Frequency

Given a vector of N positive integers and an integer X. The task is to find the frequency of X in vector.

Input:
N = 5
vector = {1, 1, 1, 1, 1}
X = 1

Output:
5

Sort Vector of Pairs

Given a vector of pairs of size n where first element of pair is the age and the second element is the height, you need to sort the vector of pairs in descending order by the second item of the pair. And if the second items are equal, then sort it by first element.

Example:
Input:
2
2
1 4 2 4
2
1 6 2 10

Output:
(2,4) (1,4)
(2,10) (1,6)

Back to Front

Given a vector of N positive integers. Your task is to print the vector elements in reverse order.

Input:
N = 5
vector -> 1 2 3 4 5

Output:
5 4 3 2 1

Josephus problem

Given the total number of persons n and a number k which indicates that k-1 persons are skipped and kth person is killed in circle in a fixed direction.

The task is to choose the safe place in the circle so that when you perform these operations starting from 1st place in the circle, you are the last one remaining and survive.

Input:
n = 3 k = 2
Output: 3

Front to Back

Iterators are used to iterate over vectors, maps, sets etc. Here you have to iterate over a vector from begin to end.
You are given a vector V of size n. You need to print its elements.

Input:
N = 5
vector -> 1 2 3 4 5
Output:
1 2 3 4 5

Elements Less Than K

A vector a of size n and an element k are given to you. You need to return the list(vector) of elements less than k. The order of elements should be the same as that in the original array.

Input:
n = 5
vector -> 5 3 6 1 3
k = 4
Output:
3 1 3

Pairing Elements

Given an array of elements of size N containing positive integers. The task is to make pair of elements given in array such that 1st element will be paired with last element, 2nd element with 2nd last, 3rd element with 3rd last and so on. If the array is of odd size then make middle element as a pair with itself.

Input Format: The input line contains T, denoting the number of testcases. For each testcase there will be two lines. The first line contains size of array N, second line contains elements of the array separated by space. Use pairs.

Output Format: For each testcase, in a new line, you need to print the pairs formed as such (arr[0],arr[N-1]) (arr[1],arr[N-2]), and so on in new line.

Constraints:
1 <= T <= 100
1 <= N <= 1000
1 <= arr[i] <= 1000

Sample Input:
2
5
1 2 3 4 5
4
4 2 3 1

Sample Output:
(1,5) (2,4) (3,3)
(4,1) (2,3)

Corresponding `pair`

Given two arrays arr1[] and arr2[] of size N. The task is to make pairs containing values corresponding from arr1 and arr2 i.e. (arr1[0], arr2[0]), (arr1[1],arr2[1]) and so on.

Input Format: The input line contains T, number of testcases. Each testcase contains three lines. The first line contains N size of both arrays. The second and third line contains elements of two arrays separated by space.

Output Format: For each testcase, in a new line, you have to return an array of pairs formed with given arrays.

Constraints:
1 <= T <= 100
1 <= N <= 100
1 <= arr1[i], arr2[j] <= 100

Sample Input:
2
5
1 2 3 4 5
6 7 8 9 10
2
1 2
3 4

Sample Output:
(1,6) (2,7) (3,8) (4,9) (5,10)
(1,3) (2,4)

Readme update of C++ STL

TASK: To update the readme of the landing page of the repo and explaining in short what are the use cases and types of C++STL Templated classes and also their built-in functions.

Deque deletion

Given a Deque dqe of size N containing non-negative integers.

Complete below functions depending type of query as mentioned and provided to you (indexing starts from 0):

  1. eraseAt(X): this function should remove the element from specified position X in deque.
  2. eraseInRange(start, end): this function should remove the elements in range start (inclusive), end (exclusive) specified in the argument of the function.
    Note: If start is equal to end then simply return.
  3. eraseAll(): remove all the elements from the deque.

Input:
5
1 2 4 5 6
1 2

Output:
1 2 5 6

Vector Erase and Clear

Given a Vector V of size N containing integers. Complete below functions on given vector depending on type of erasable query

  1. clearAll(): This function removes all elements from vector.
  2. eraseAt(): This function removes element from specified position present in the vector.
  3. eraseInRange(): This function removes element from vector in the given range start & end.

Stack Insertion

Hi,
I would like to add a C++ code representing insertion of elements in a stack using C++ STL.
@Ankit152

Regards,
Debanjan Poddar

Dequeue Traversal

Given a Deque Deq containing N elements, the task is to traverse the Deq and print the elements of it.

Input:
5
1 2 3 4 5

Output:
1 2 3 4 5

Maximum Of All Subarrays Of Size K Using Dequeue

Given an array A and an integer K. Find the maximum for each and every contiguous subarray of size K.

Input:
2
9 3
1 2 3 1 4 5 2 3 6
10 4
8 5 10 7 9 4 15 12 90 13

Output:
3 3 4 5 5 5 6
10 10 10 15 15 90 90

Removing consecutive duplicates

You are given string str. You need to remove the consecutive duplicates from the given string using a Stack.

Input:
aaaaaabaabccccccc

Output:
ababc

Insertion in deque

Given an array arr[] of size N containing non-negative integers. You need to insert all elements of the array to deque and return it.

Input:
5
1 2 3 4 5

Output:
1 2 3 4 5

Parenthesis Checker

Given an expression string x. Examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in exp.
For example, the function should return 'true' for exp = “[()]{}{()()}” and 'false' for exp = “[(])”.

Input:
{([])}
Output:
true

Make Pair

Given two elements X and Y. The task is to return the pair formed from a function makePair with given elements. Use make_pair from Pair.

Constraints:
1 <= T <= 100
1 <= X, Y <= 1000

Sample Input:
2
4 5
1 0

Sample Output:
(4,5)
(1,0)

Vector Sum

Given a vector, find the sum of the elements of this vector.

Input:
10 20 30

Output:
60

Forward List Insert

You are given an array of size n. You need to insert the elements of this array in to a forward list.

Input:
1
5
1 2 3 4 5
Output:
5 4 3 2 1

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.