text stringlengths 1 24.5M |
|---|
#ifndef COLOR_H
#define COLOR_H
#include <ostream>
namespace Color {
enum class Code {
BOLD = 1,
RESET = 0,
BG_BLUE = 44,
BG_DEFAULT = 49,
BG_GREEN = 42,
BG_RED = 41,
FG_BLACK = 30,
FG_BLUE = 34,
FG_CYAN = 36,
FG_DARK_GRAY = 90,
FG_DEFAULT = 39,
FG_GREEN = 32,
FG_LIGHT_BLUE = 94,
FG_LIGHT_... |
#ifndef GAMEGRAPHICS_H
#define GAMEGRAPHICS_H
#include <string>
#include <tuple>
enum GameBoardDimensions {
MIN_GAME_BOARD_PLAY_SIZE = 3,
MAX_GAME_BOARD_PLAY_SIZE = 10
};
enum { COMPETITION_GAME_BOARD_PLAY_SIZE = 4 };
namespace Game {
namespace Graphics {
std::string AsciiArt2048();
std::string BoardInputPrompt(... |
#ifndef GAMEINPUT_H
#define GAMEINPUT_H
#include <array>
namespace Game {
namespace Input {
namespace Keypress {
namespace Code {
enum { CODE_ESC = 27, CODE_LSQUAREBRACKET = '[' };
// Hotkey bindings:
// Style: ANSI (Arrow Keys)
enum {
CODE_ANSI_TRIGGER_1 = CODE_ESC,
CODE_ANSI_TRIGGER_2 = CODE_LSQUAREBRACKET
}... |
#ifndef GAMEPREGAMEMENU_H
#define GAMEPREGAMEMENU_H
#include <string>
namespace Game {
namespace PreGameSetup {
void SetUpNewGame();
void ContinueOldGame(const std::string& filename);
} // namespace PreGameSetup
} // namespace Game
#endif
|
#ifndef GAME_H
#define GAME_H
#include <string>
namespace Game {
struct GameBoard;
enum class PlayGameFlag { BrandNewGame, ContinuePreviousGame };
void playGame(PlayGameFlag cont, GameBoard gb,
unsigned long long userInput_PlaySize = 1);
void startGame();
void continueGame(const std::string& filename);... |
#ifndef GAMEBOARDGRAPHICS_H
#define GAMEBOARDGRAPHICS_H
#include <string>
namespace Game {
struct GameBoard;
namespace Gameboard {
namespace Graphics {
std::string GameBoardTextOutput(GameBoard gb);
}
} // namespace Gameboard
} // namespace Game
#endif
|
#ifndef GAMEBOARD_H
#define GAMEBOARD_H
#include "tile.hpp"
#include <tuple>
#include <vector>
struct point2D_t;
namespace Game {
struct GameBoard {
using tile_data_array_t = std::vector<tile_t>;
using gameboard_data_array_t = std::tuple<size_t, tile_data_array_t>;
gameboard_data_array_t gbda;
bool win{};
... |
#ifndef GLOBAL_H
#define GLOBAL_H
#include <iosfwd>
#include <string>
using ull = unsigned long long;
void getKeypressDownInput(char &);
template<typename T>
void DrawAlways(std::ostream &os, T f) {
os << f();
}
template<typename T>
void DrawOnlyWhen(std::ostream &os, bool trigger, T f) {
if (trigger) {
Dra... |
#ifndef LOADRESOURCE_H
#define LOADRESOURCE_H
#include <string>
#include <tuple>
namespace Game {
using load_gameboard_status_t = std::tuple<bool, struct GameBoard>;
namespace Loader {
load_gameboard_status_t load_GameBoard_data_from_file(std::string filename);
// Output: {[loadfile_ok_status], [decltype(gameboard.... |
#ifndef MENUGRAPHICS_H
#define MENUGRAPHICS_H
#include <string>
namespace Game {
namespace Graphics {
namespace Menu {
std::string MainMenuTitlePrompt();
std::string MainMenuOptionsPrompt();
std::string InputMenuErrorInvalidInputPrompt();
std::string InputMenuPrompt();
std::string MainMenuGraphicsOverlay(bool input_e... |
#ifndef MENU_H
#define MENU_H
#include <array>
#include "gameboard.hpp"
/**
* @enum MainMenuStatusFlag
* @brief Enumeration of possible main menu status flags.
*
* These flags represent various states and actions that can be triggered from the main menu.
*/
enum MainMenuStatusFlag {
FLAG_NULL, ... |
#ifndef POINT_2D_H
#define POINT_2D_H
#include <tuple>
class point2D_t {
// Simple {x,y} datastructure = std::tuple<int, int>...
using point_datatype_t = typename std::tuple<int, int>;
point_datatype_t point_vector{};
explicit point2D_t(const point_datatype_t pt) : point_vector{pt} {}
public:
enum class Po... |
#ifndef SAVERESOURCE_H
#define SAVERESOURCE_H
#include <string>
#include <tuple>
namespace Game {
struct GameBoard;
namespace Saver {
void saveGamePlayState(GameBoard gb, const std::string& filename);
} // namespace Saver
} // namespace Game
#endif
|
#ifndef SCORESGRAPHICS_H
#define SCORESGRAPHICS_H
#include <string>
#include <tuple>
#include <vector>
namespace Scoreboard {
namespace Graphics {
using scoreboard_display_data_t =
std::tuple<std::string, std::string, std::string, std::string, std::string,
std::string, std::string>;
using scoreboa... |
#ifndef SCORES_H
#define SCORES_H
#include "global.hpp"
#include <iosfwd>
#include <string>
#include <tuple>
#include <vector>
namespace Scoreboard {
struct Score {
std::string name;
ull score;
bool win;
ull largestTile;
long long moveCount;
double duration;
};
bool operator>(const Score &a, const Score ... |
#ifndef STATISTICSGRAPHICS_H
#define STATISTICSGRAPHICS_H
#include <string>
#include <tuple>
namespace Statistics {
namespace Graphics {
std::string AskForPlayerNamePrompt();
std::string MessageScoreSavedPrompt();
using total_stats_display_data_t =
std::tuple<bool, std::string, std::string, std::string, std::str... |
#ifndef STATISTICS_H
#define STATISTICS_H
#include "global.hpp"
#include <iosfwd>
#include <string>
#include <tuple>
namespace Scoreboard {
struct Score;
}
namespace Statistics {
struct total_game_stats_t {
ull bestScore{};
ull totalMoveCount{};
int gameCount{};
double totalDuration{};
int winCount{};
};
... |
#ifndef TILEGRAPHICS_H
#define TILEGRAPHICS_H
#include <string>
namespace Game {
struct tile_t;
std::string drawTileString(tile_t currentTile);
} // namespace Game
#endif
|
#ifndef TILE_H
#define TILE_H
#include "global.hpp"
namespace Game {
struct tile_t {
ull value{};
bool blocked{};
};
} // namespace Game
#endif
|
// Demonstrates empty()
#include <iostream>
#include <map>
int main() {
// declaration of map container
std::map<char, int> mymap;
mymap['a'] = 1;
mymap['b'] = 2;
mymap['c'] = 3;
// using empty() to check map is empty or not
if(mymap.empty()==true)
printf("my map is emp... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Harsh Raj
Date : 15/08/2019
Time : 12:30 AM
Description : accumulate() function is used to perform certain operations on the range of iterators provided. It takes two iterators and initial value a... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : GOSHROW
Date : 12/10/2019
Time : 23:30
Description : Performs operations (difference by default) on adjacent pairs in an iterator.
*/
#include <iostream> // std::cout
#include <... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Copies the elements in one range to another range.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> origin {1, 2, 3};
std::vector<int> destination;
/... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Copies elements from range to another range ending in argument.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> origin {1, 2, 3};
// destination size is ... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Copies the elements in one range to another range if it matches a condition.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
auto isOdd = [](int i) {
return ((i%2) ==... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Copies n elements starting at a position to another range.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> origin {1, 2, 3};
std::vector<int> destination... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Bhupesh Varshney
Date : 19/02/2019
Time : 5:10 PM
Description : number of elements in the range `[first, last)` satisfying specific criteria.
*/
#include<iostream>
#include<vector>
#incl... |
/*
Author: Michael Guzman
Date: 10/16/2019
Time: 19:43
Description: Compares the elements of two vectors in the given range.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::vector<int> v1 {3, 5, 3, 1, 2, 3};
std::vector<int> v2 {1, 2 ,3, 4, 5, 6};
std::vecto... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 23:00
Description : Retrieve smallest element that is not smaller than given value.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> vec = {1, 2, 3, 1, 6, 1};
// equal_range... |
/*
Author : Italo Vinicius
Date : 01/10/2019
Time : 22:00
Description : Can fill in specific positions a specific number.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> v(10);
//Lets print what we have in the vector
for(int i = 0;i<10;i++)... |
/*
Author : Klajdi Bodurri
Date : 08/01/2020
Time : 14:00
Description : Show an example of fill_n
*/
#include <iostream>
#include <vector>
#include <algorithm>
void print_vector(const std::vector<int> &v) {
// iterate through v and print its elements
for(auto &elem:v) {
std::cout << elem <... |
/*
Author : Derek Hornacek
Date : 16/03/2020
Time : 05:24pm
Description : This is a code snippet demonstrating the find_end algorithm from the C++ STL.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main(){
std::vector<int> sequence{ 13, 5, 2, };
std::vector<int> target{ 18, 11, 7... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Checks if a range is included in another range.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> v1 {8, 2, 0, 4};
std::vector<int> v2 {2, 0};
std::vec... |
/*
Author : Claudio Montanari
Date : 26/06/1995
Time : 15:30
Description : Computes inclusive prefix binary operation on a range (sum by default).
*/
#include <iostream>
#include <vector>
#include <numeric>
#include <iterator>
int main() {
std::vector<int> v{ 1, 2, 3, 4, 3, 10 };
std::cou... |
/*
Author : Klajdi Bodurri
Date : 05/01/2020
Time : 16:07 PM
Description : Shows two different usages of inner_product().
*/
#include <iostream>
#include <vector>
#include <numeric>
/* Custom accumultor behaviour for inner_product.
* In this example the custom accumulator function happens to have the... |
/*
Author : Abhay Singh Yadav
Date : Date format 21/10/2019
Time : Time format 21:20
Description : Finding the first unsorted element in the range [first, last).
It returns an iterator to the first unsorted element in the range.
*/
#include <iostream>
#include <algorithm>
int ... |
#include <iostream>
#include <algorithm>
bool compare(const char& a, const char& b) {
// Case insensitive lexicographical check
return std::tolower(a) < std::tolower(b);
}
int main() {
std::string s = "ThisComesFirst";
std::string t = "aaa...stillthiscomessecond";
// Use lexicographical_compare t... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 23:00
Description : Retrieve smallest element that is not smaller than given value.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> vec = {3, -1, 2, 5, 10, 6, 7, 4};
// low... |
#include<iostream>
#include<vector>
#include<algorithm>
int main(){
//sample vector
std::vector<int> v1 = {2,5,8,7,4,5};
//printing first element
std::cout << "First element before making heap : " << v1.front() << std::endl;
//outputs 2
//transforming vector into heap with make_heap()... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 23:00
Description : Compares two values, returning the greatest.
*/
#include <iostream>
#include <algorithm>
int main() {
int a = 7, b = 3;
auto greatest = std::max(a, b);
// prints 7
std::cout << greatest <<... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 23:00
Description : Retrieve the greatest value from a range.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> vec = {3, -1, 2, 10, 4};
auto greatestIt = std::max_element(v... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Merge two ranges into a new destination.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> v1 {8, 2, 0, 4};
std::vector<int> v2 {7, 3, 5};
// the desti... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 23:00
Description : Compares two values, returning the smallest.
*/
#include <iostream>
#include <algorithm>
int main() {
int a = 7, b = 3;
auto smallest = std::min(a, b);
// print 3
std::cout << smallest << ... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Ian Fillipe Pontes Ferreira
Date : 07/10/2019
Time : 19:32
Description : Returns the smallest and the greatest of the values in array... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 23:00
Description : Retrieve min and max of values or from a list.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
int a = 7, b = 3;
// returns pair <3, 7>
auto minMax1 = std::minm... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 23:00
Description : Retrieve the smallest and greatest value from a range.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> vec = {3, -1, 2, 10, 4};
auto minMaxPair = std::... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 23:00
Description : Retrieve the smallest value from a range.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> vec = {3, -1, 2, 10, 4};
auto smallestIt = std::min_element(v... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Ian Fillipe Pontes Ferreira
Date : 06/10/2019
Time : 20:25
Description : Is an STL algorithm which rearranges the list in such a way ... |
/*
Author : David Bezhanishvili
Date : 14/06/2020
Time : 18:25
Description : move n smallest elements to the beginning of an array
*/
#include <algorithm>
#include <vector>
#include <iostream>
int main()
{
int n=3; //move 3 smallest elements to the beginning
std::vector<int> v = {5, 7, 4, 2, ... |
/*
Author : Eduardo Magalhaes
Date : 09/10/2020
Time : 14:24
Description : Copies the elements in the range [first,last) for which pred returns true into the range pointed by result_true, and those for which it does not into the range pointed by result_false.
*/
#include <iostream>
#include <algorithm>... |
#include<iostream>
#include<vector>
#include<algorithm>
int main(){
//sample vector
std::vector<int> v1 = {2,5,8,7,4,5};
//converting vector into heap
make_heap(v1.begin(),v1.end());
//printing first element
std::cout << "first element of the heap: " << v1.front() << std::endl;
//outpu... |
/*
Author : Ajay Makwana
Date : Date format 12/10/2019
Time : Time format 12:46 AM
Description : Randomly Shuffle Element of user defined vector.
*/
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main() {
srand(unsigned(time(0)));
vector<int> arr;
// s... |
/*
Author : Thamara Andrade
Date : Date format 09/09/2019
Time : Time format 23:00
Description : Removes elements from vector that satisfies a criteria.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> v {3, 5, 3, 1, 2, 3};
// remove all elements tha... |
/*
Author : Thamara Andrade
Date : Date format 09/09/2019
Time : Time format 23:00
Description : Removes elements from vector that satisfies a criteria.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> origin {3, 5, 3, 1, 2, 3};
std::vector<int> desti... |
/*
Author : Thamara Andrade
Date : Date format 09/09/2019
Time : Time format 23:00
Description : Copies elements from a range to another removing the ones that satisfies a criteria.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
auto isOdd = [](int i) {
return (... |
/*
Author : Thamara Andrade
Date : Date format 09/09/2019
Time : Time format 23:00
Description : Removes elements from vector that satisfies a criteria.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
auto isOdd = [](int i) {
return ((i%2) == 1);
};
std:... |
/*
Author : Thamara Andrade
Date : Date format 09/09/2019
Time : Time format 23:00
Description : Replace elements from vector by a new value.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> origin {3, 5, 3, 1, 2, 3};
// replaces 3 by 0
std::repl... |
/*
Author : Thamara Andrade
Date : Date format 09/09/2019
Time : Time format 23:00
Description : Copies elements from a range to another replacing the ones that satisfies a criteria.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> origin {3, 5, 3, 1, 2, ... |
/*
Author : Thamara Andrade
Date : Date format 09/09/2019
Time : Time format 23:00
Description : Copies elements from a range to another replacing the ones that satisfies a criteria.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
auto isOdd = [](int i) {
return ... |
/*
Author : Thamara Andrade
Date : Date format 09/09/2019
Time : Time format 23:00
Description : Replace elements from vector by a new value.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
auto isOdd = [](int i) {
return ((i%2) == 1);
};
std::vector<int... |
/*
Author : Akash Goyal
Date : 09/10/2019
Time : 09:23
Description : Rotate the elements of vector in clockwise or anti-clockwise direction.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> vec1{1, 2, 3, 4, 5};
// Printing initial elements of vector: 1 2 ... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : this must be your name ;)
Date : Date format dd/mm/yyyy
Time : Time format hh:mm
Description : description should be small & one liner... |
/*
Author : Luca Palumbo
Date : Date format 07/10/2019
Time : Time format 23:00
Description : Search the position of a subarray in a vector.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main(){
// defining two vector
std::vector<int> haystack { 10, 20, 30, 40, 50, 60, 70, 80, 90 ... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Computes the difference between two ranges.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> v1 {3, 1, 5};
std::vector<int> v2 {1, 0};
// the destina... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Computes the intersection of two ranges.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> v1 {3, 1, 5};
std::vector<int> v2 {1, 0};
// the destinatio... |
/*
Author : Sarah Leon
Date : 06/04/2020
Time : 08:20
Description : Compares two sets and fills a container with their difference.
*/
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
//intialize arrays, must be sorted
int firstArray[5] = { 0, 2, 4, 6, 8 };
int secon... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Computes the union of two ranges.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
std::vector<int> v1 {3, 1, 5};
std::vector<int> v2 {1, 0};
// the destination needs... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Ian Fillipe Pontes Ferreira
Date : 06/10/2019
Time : 20:41
Description : Rearranges the elements in the range randomly
*/
#include <i... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Luis Malicay
Date : 06/06/2019
Time : 12:28 PM
Description : Sort the elements in a container in ascending order.
*/
#include <algorit... |
/*
Author : Italo Vinicius
Date : 01/10/2020
Time : 21:28 PM
Description : Sorts a heap within the range specified by start and end.
*/
#include <algorithm>
#include <vector>
#include <iostream>
int main()
{
std::vector<int> v = {3, 1, 4, 1, 5, 9};
std::make_heap(v.begin(), v.end());
... |
#include<bits/stdc++.h>
int main(){
//sample array
int ar[] = {1,1,3,5,4,9,4};
//sorting the array
std::stable_sort(ar,ar+7);
//array after sorting
for(int i = 0;i < 7;i++){
std::cout << ar[i] << " ";
}
//outputs 1 1 3 4 4 5 9
return 0;
}
|
/*
Author : duongoku
Date : 10/1/2019
Time : 21:25
Description : Exchange values of two objects
*/
#include <iostream>
#include <algorithm>
int main(){
//Declare two example objects (same type)
int a = 60, b = 50;
//a:60 and b:50
std::cout << "Before : a = " << a << " and b = " << b << "\n";
s... |
/*
Author : Nishanth Sanjeev
Date : 07/10/2019
Time : 22:57
Description : A simple function that converts a numerical value to a string.
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
// An example of converting an integer value to a string.
std::string str1 = std::to_string(3456... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Ian Fillipe Pontes Ferreira
Date : 06/10/2019
Time : 20:41
Description : Using transform function of STL, we can add arrays in single... |
/*
Author : Eduardo Magalhaes
Date : 09/10/2020
Time : 14:24
Description : Copies the elements in the range [first,last) to the range beginning at result, except consecutive duplicates (elements that compare equal to the element preceding).
*/
#include <string>
#include <iostream>
#include <algorithm>
... |
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 23:00
Description : Retrieve smallest element that greater than given value.
*/
#include <iostream>
#include<algorithm>
#include<set>
void show(int a[], int arraysize) {
for (int i = 0; i < arraysize; ++i) {
... |
/*
Author : Nishanth Sanjeev
Date : 07/10/2019
Time : 21:45
Description : Finding gcd of two numbers, with only a function call
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int num1 = 18;
int num2 = 4;
// An example of finding gcd() of these two numbers.
// The answ... |
/*
Author : Sajjad Bin Samad
Date : 15/10/2019
Time : 12:02
Description : This function is used to extend list by inserting new element at a given position.
*/
#include <iostream>
#include <list>
int main (){
// declaration of list
std::list< std::pair<int,char> > mylist;
... |
/*
Author : Avneesh Kumar
Date : 14/01/2020
Time : 23:37
Description : This function is used to find maximum number of elements a list container can hold.
*/
#include <iostream>
#include <list>
using namespace std;
int main(){
// Creating a list
std::list<int> demoList;
// chec... |
/*
Author : Howard Jiang
Date : December 1, 2019
Time : 05:22
Description : This function merges two sorted lists of the same size using a comparator function.
*/
#include<iostream>
#include<list>
//This comparer function creates a strict weak ordering of the values in the lists, it doesn't sort the list.
... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Nicole Spoto
Date : 10/10/2019
Time : 01:30 PM
Description : pop_back() function is used to remove the last element in the list container and the size of the list is decreased by 1.
*/
... |
/*
Author : Shameer Ahmad
Date : 25/10/2019
Time : 05:26
Description : This function is used to reverse the content of a list.
*/
#include <iostream>
#include <list>
int main(){
// initializing a list
std::list<int> mylist{1, 2, 3, 4};
//calling the reverse function
mylist.reverse();... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : this must be your name ;)
Date : Date format dd/mm/yyyy
Time : Time format hh:mm
Description : description should be small & one liner... |
/*
Author : Y. Sai Sriram
Date : 29/09/2019
Time : 11:26
Description : This function is used to swap the contents of one list with another list of same type and size.
*/
#include<iostream>
#include<list>
int main(){
// list container declaration
std::list<int> mylist1{1, 2, 3, 4};
std::list<i... |
/*
Author : Shashank T D
Date : 16/10/2019
Time : 14:30
Description : This program demonstrates the usage of unique function for a list
*/
#include <iostream>
#include <cmath>
#include <list>
// removes the second element if consecutive element difference is less than 2
bool differenceOfTwo(int f... |
/*
Author : Manav Sethi
Date : 26/06/2019
Time : 21:52
Description : demonstration of begin and end function in map
*/
#include <iostream>
#include <map>
int main ()
{
std::map<char,int> mymap;
mymap['b'] = 100;
mymap['a'] = 200;
mymap['c'] = 300;
// show content:
for (std::map<char,int>... |
/*
Author : Kabindra Shrestha
Date : Date format 19/10/2019
Time : Time format 21:20
Description : Removes all the elements of the map container
*/
#include <bits/stdc++.h>
#include <iostream>
#include <map>
void printMap(std::map<char, int> &asciiMap){
std::map<char, int>::iterator it;
std::cout ... |
/*
Author : Liel Fridman
Date : 25/10/2019
Time : 16:13
Description : create a simple map and test for two keys: 1 and 2.
*/
#include <iostream>
#include <map>
int main() {
/* Should print:
2 found.
1 not found. */
std::map<int, int> example = {{2, 3}, {4, 5}};
if (example.contain... |
/*
Author : Nikhit
Date : 20/10/2019
Time : 16:15
Description : Demonstration the emplace key-value pair in STL map
*/
#include <iostream>
#include <string>
#include <map>
int main() {
// creating a container and inserting values using "emplace" function
std::map<std::string, int> ages;
ag... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Luis Malicay
Date : 07/06/2019
Time : 2:25 PM
Description : Test if the map container is empty
*/
#include <iostream>
#include <map>
#... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Luis Malicay
Date : 06/06/2019
Time : 12:43 PM
Description : Demonstrate the insert key value pair of STL map
*/
#include <iostream>
#... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : this must be your name ;)
Date : Date format dd/mm/yyyy
Time : Time format hh:mm
Description : description should be small & one liner... |
/*
Author : Kabindra Shrestha
Date : Date format 25/10/2019
Time : Time format 12:28
Description : returns the size of the map, i.e. the number of elements in
the map
*/
#include <iostream>
#include <map>
// Prints the current size of the map
void printSize(std::map<char, int> &asciiMap){
std::co... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Timothy Itodo
Date : 28/05/2019
Time : 1:00 PM
Description : back() function is used to reference the last element (i.e the newest element) of the queue. This function can be used to fetch the last ... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Timothy Itodo
Date : 30/05/2019
Time : 01:00 PM
Description : emplace() function is used to add a new element at the end of the queue, after its current last element. The element is added to the que... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Timothy Itodo
Date : 30/05/2019
Time : 01:00 PM
Description : empty() function is used to check if the queue container is empty or not. This function returns true, if the queue is empty or false, ot... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Timothy Itodo
Date : 28/05/2019
Time : 1:00 PM
Description : front() function is used to reference the first element (ie. the oldest element) of the queue. This function can be used to fetch the fir... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Rickey Patel
Date : 23/05/2019
Time : 03:50 PM
Description : pop() function is used to remove an element from the front of the queue (ie. the oldest element in the queue). The element is... |
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Rickey Patel
Date : 23/05/2019
Time : 03:50 PM
Description : push() function is used to insert an element at the back of the queue. The element is added to the queue container and the si... |
// Follow the Style Guide while submitting code PR.
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : this must be your name ;)
Date : Date format dd/mm/yyyy
Time : Time format hh:mm
Description : description should be small & one liner... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.