mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-22 12:52:48 +08:00
469 lines
29 KiB
HTML
469 lines
29 KiB
HTML
<!-- HTML header for doxygen 1.12.0-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.14.0"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>TheAlgorithms/C++: operations_on_datastructures Namespace Reference</title>
|
|
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
|
|
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../jquery.js"></script>
|
|
<script type="text/javascript" src="../../dynsections.js"></script>
|
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
|
|
<script type="text/javascript">
|
|
DoxygenAwesomeDarkModeToggle.init()
|
|
</script>
|
|
<script type="text/javascript" src="../../clipboard.js"></script>
|
|
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../navtreedata.js"></script>
|
|
<script type="text/javascript" src="../../navtree.js"></script>
|
|
<script type="text/javascript" src="../../cookie.js"></script>
|
|
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
|
<script type="text/javascript" src="../../search/search.js"></script>
|
|
<script type="text/javascript">
|
|
window.MathJax = {
|
|
options: {
|
|
ignoreHtmlClass: 'tex2jax_ignore',
|
|
processHtmlClass: 'tex2jax_process'
|
|
},
|
|
loader: {
|
|
load: ['[tex]/ams']
|
|
},
|
|
tex: {
|
|
macros: {},
|
|
packages: ['base','configmacros','ams']
|
|
}
|
|
};
|
|
</script>
|
|
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
|
|
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
|
<link href="../../doxygen-awesome.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr id="projectrow">
|
|
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
|
|
<td id="projectalign">
|
|
<div id="projectname">TheAlgorithms/C++<span id="projectnumber"> 1.0.0</span>
|
|
</div>
|
|
<div id="projectbrief">All the algorithms implemented in C++</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.14.0 -->
|
|
<script type="text/javascript">
|
|
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
|
</script>
|
|
<script type="text/javascript">
|
|
$(function() { codefold.init(); });
|
|
</script>
|
|
<script type="text/javascript" src="../../menudata.js"></script>
|
|
<script type="text/javascript" src="../../menu.js"></script>
|
|
<script type="text/javascript">
|
|
$(function() {
|
|
initMenu('../../',true,false,'search.php','Search',true);
|
|
$(function() { init_search(); });
|
|
});
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
$(function(){initNavTree('da/d6d/namespaceoperations__on__datastructures.html','../../',''); });
|
|
</script>
|
|
<div id="container">
|
|
<div id="doc-content">
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<div id="MSearchResults">
|
|
<div class="SRPage">
|
|
<div id="SRIndex">
|
|
<div id="SRResults"></div>
|
|
<div class="SRStatus" id="Loading">Loading...</div>
|
|
<div class="SRStatus" id="Searching">Searching...</div>
|
|
<div class="SRStatus" id="NoMatches">No Matches</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="headertitle"><div class="title">operations_on_datastructures Namespace Reference</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p>for std::vector
|
|
<a href="#details">More...</a></p>
|
|
<table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 id="header-func-members" class="groupheader"><a id="func-members" name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:a6109193567a5b7e36a27f2b4865fce20" id="r_a6109193567a5b7e36a27f2b4865fce20"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="#a6109193567a5b7e36a27f2b4865fce20">print</a> (const std::vector< int32_t > &array)</td></tr>
|
|
<tr class="memdesc:a6109193567a5b7e36a27f2b4865fce20"><td class="mdescLeft"> </td><td class="mdescRight">Prints the values of a vector sequentially, ending with a newline character. <br /></td></tr>
|
|
<tr class="memitem:afce39cf843989a39811a49ebe29dd6d8" id="r_afce39cf843989a39811a49ebe29dd6d8"><td class="memItemLeft" align="right" valign="top">std::vector< int32_t > </td><td class="memItemRight" valign="bottom"><a class="el" href="#afce39cf843989a39811a49ebe29dd6d8">shift_left</a> (const std::vector< int32_t > &array, size_t shift)</td></tr>
|
|
<tr class="memdesc:afce39cf843989a39811a49ebe29dd6d8"><td class="mdescLeft"> </td><td class="mdescRight">Shifts the given vector to the left by the shift amount and returns a new vector with the result. The original vector is not mutated. <br /></td></tr>
|
|
<tr class="memitem:a1bfb8711f49e591eb168ccaa3df6fb86" id="r_a1bfb8711f49e591eb168ccaa3df6fb86"><td class="memItemLeft" align="right" valign="top">std::vector< int32_t > </td><td class="memItemRight" valign="bottom"><a class="el" href="#a1bfb8711f49e591eb168ccaa3df6fb86">shift_right</a> (const std::vector< int32_t > &array, size_t shift)</td></tr>
|
|
<tr class="memdesc:a1bfb8711f49e591eb168ccaa3df6fb86"><td class="mdescLeft"> </td><td class="mdescRight">Shifts the given vector to the right by the shift amount and returns a new vector with the result. The original vector is not mutated. <br /></td></tr>
|
|
<tr class="memitem:adaf9a06f0c236c2d95c97e441ea2d12e" id="r_adaf9a06f0c236c2d95c97e441ea2d12e"><td class="memItemLeft" align="right" valign="top">std::vector< int32_t > </td><td class="memItemRight" valign="bottom"><a class="el" href="#adaf9a06f0c236c2d95c97e441ea2d12e">get_intersection</a> (const std::vector< int32_t > &first, const std::vector< int32_t > &second)</td></tr>
|
|
<tr class="memdesc:adaf9a06f0c236c2d95c97e441ea2d12e"><td class="mdescLeft"> </td><td class="mdescRight">Gets the intersection of two sorted arrays, and returns them in a vector. <br /></td></tr>
|
|
<tr class="memitem:a2b8ff06a84b041457873840bf82e2d74" id="r_a2b8ff06a84b041457873840bf82e2d74"><td class="memItemLeft" align="right" valign="top">std::vector< int32_t > </td><td class="memItemRight" valign="bottom"><a class="el" href="#a2b8ff06a84b041457873840bf82e2d74">get_union</a> (const std::vector< int32_t > &first, const std::vector< int32_t > &second)</td></tr>
|
|
<tr class="memdesc:a2b8ff06a84b041457873840bf82e2d74"><td class="mdescLeft"> </td><td class="mdescRight">Gets the union of two sorted arrays, and returns them in a vector. <br /></td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 id="header-details" class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p>for std::vector </p>
|
|
<p>for std::priority_queue</p>
|
|
<p>For std::vector.</p>
|
|
<p>for assert for IO operations</p>
|
|
<p>Operations on Data Structures</p>
|
|
<p>for assert for IO Operations</p>
|
|
<p>Operations on data structures</p>
|
|
<p>for std::sort for assert for IO operations</p>
|
|
<p>Operations on Data Structures</p>
|
|
<p>For assert For IO operations For std::queue</p>
|
|
<p>Operations on Data Structures</p>
|
|
<p>for std::count for assert for tolower for std::uint32_t for string operations for IO Operations</p>
|
|
<p>Operations on data structures </p>
|
|
</div><a name="doc-func-members" id="doc-func-members"></a><h2 id="header-doc-func-members" class="groupheader">Function Documentation</h2>
|
|
<a id="adaf9a06f0c236c2d95c97e441ea2d12e" name="adaf9a06f0c236c2d95c97e441ea2d12e"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#adaf9a06f0c236c2d95c97e441ea2d12e">◆ </a></span>get_intersection()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">std::vector< int32_t > operations_on_datastructures::get_intersection </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const std::vector< int32_t > &</td> <td class="paramname"><span class="paramname"><em>first</em></span>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const std::vector< int32_t > &</td> <td class="paramname"><span class="paramname"><em>second</em></span> )</td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Gets the intersection of two sorted arrays, and returns them in a vector. </p>
|
|
<p>An algorithm is used that compares the elements of the two vectors, incrementing the index of the smaller of the two. If the elements are the same, the element is appended to the result array to be returned. </p><dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">first</td><td>A std::vector of sorted integer values </td></tr>
|
|
<tr><td class="paramname">second</td><td>A std::vector of sorted integer values </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>A std::vector of the intersection of the two arrays, in ascending order </dd></dl>
|
|
<p>< Vector to hold the intersection</p>
|
|
<p>< Index for the first array</p>
|
|
<p>< Index for the second array</p>
|
|
<p>< Length of first array</p>
|
|
<p>< Length of second array</p>
|
|
<p>< Increment index of second array</p>
|
|
<p>< Increment index of second array</p>
|
|
<p>< Add the element if it is unique</p>
|
|
<p>< Increment index of first array</p>
|
|
<p>< Increment index of second array too</p>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../de/dc5/intersection__of__two__arrays_8cpp_source.html#l00049">49</a> of file <a class="el" href="../../de/dc5/intersection__of__two__arrays_8cpp_source.html">intersection_of_two_arrays.cpp</a>.</p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 50</span> {</div>
|
|
<div class="line"><span class="lineno"> 51</span> std::vector<int32_t> res; </div>
|
|
<div class="line"><span class="lineno"> 52</span> <span class="keywordtype">size_t</span> f_index = 0; </div>
|
|
<div class="line"><span class="lineno"> 53</span> <span class="keywordtype">size_t</span> s_index = 0; </div>
|
|
<div class="line"><span class="lineno"> 54</span> <span class="keywordtype">size_t</span> f_length = first.size(); </div>
|
|
<div class="line"><span class="lineno"> 55</span> <span class="keywordtype">size_t</span> s_length = second.size(); </div>
|
|
<div class="line"><span class="lineno"> 56</span> </div>
|
|
<div class="line"><span class="lineno"> 57</span> <span class="keywordflow">while</span> (f_index < f_length && s_index < s_length) {</div>
|
|
<div class="line"><span class="lineno"> 58</span> <span class="keywordflow">if</span> (first[f_index] < second[s_index]) {</div>
|
|
<div class="line"><span class="lineno"> 59</span> f_index++; </div>
|
|
<div class="line"><span class="lineno"> 60</span> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (first[f_index] > second[s_index]) {</div>
|
|
<div class="line"><span class="lineno"> 61</span> s_index++; </div>
|
|
<div class="line"><span class="lineno"> 62</span> } <span class="keywordflow">else</span> {</div>
|
|
<div class="line"><span class="lineno"> 63</span> <span class="keywordflow">if</span> ((res.size() == 0) || (first[f_index] != res.back())) {</div>
|
|
<div class="line"><span class="lineno"> 64</span> res.push_back(</div>
|
|
<div class="line"><span class="lineno"> 65</span> first[f_index]); </div>
|
|
<div class="line"><span class="lineno"> 66</span> }</div>
|
|
<div class="line"><span class="lineno"> 67</span> f_index++; </div>
|
|
<div class="line"><span class="lineno"> 68</span> s_index++; </div>
|
|
<div class="line"><span class="lineno"> 69</span> }</div>
|
|
<div class="line"><span class="lineno"> 70</span> }</div>
|
|
<div class="line"><span class="lineno"> 71</span> <span class="keywordflow">return</span> res;</div>
|
|
<div class="line"><span class="lineno"> 72</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a2b8ff06a84b041457873840bf82e2d74" name="a2b8ff06a84b041457873840bf82e2d74"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a2b8ff06a84b041457873840bf82e2d74">◆ </a></span>get_union()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">std::vector< int32_t > operations_on_datastructures::get_union </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const std::vector< int32_t > &</td> <td class="paramname"><span class="paramname"><em>first</em></span>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const std::vector< int32_t > &</td> <td class="paramname"><span class="paramname"><em>second</em></span> )</td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Gets the union of two sorted arrays, and returns them in a vector. </p>
|
|
<p>An algorithm is used that compares the elements of the two vectors, appending the one that has a lower value, and incrementing the index for that array. If one of the arrays reaches its end, all the elements of the other are appended to the resultant vector. </p><dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">first</td><td>A std::vector of sorted integer values </td></tr>
|
|
<tr><td class="paramname">second</td><td>A std::vector of sorted integer values </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>A std::vector of the union of the two arrays, in ascending order </dd></dl>
|
|
<p>< Vector to hold the union</p>
|
|
<p>< Index for the first array</p>
|
|
<p>< Index for the second array</p>
|
|
<p>< Length of first array</p>
|
|
<p>< Length of second array</p>
|
|
<p>< Integer to store value of the next element</p>
|
|
<p>< Append from first array</p>
|
|
<p>< Increment index of second array</p>
|
|
<p>< Append from second array</p>
|
|
<p>< Increment index of second array</p>
|
|
<p>< Element is the same in both</p>
|
|
<p>< Increment index of first array</p>
|
|
<p>< Increment index of second array too</p>
|
|
<p>< Add the element if it is unique</p>
|
|
<p>< Add remaining elements</p>
|
|
<p>< Add the element if it is unique</p>
|
|
<p>< Add remaining elements</p>
|
|
<p>< Add the element if it is unique</p>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../d8/d9c/union__of__two__arrays_8cpp_source.html#l00049">49</a> of file <a class="el" href="../../d8/d9c/union__of__two__arrays_8cpp_source.html">union_of_two_arrays.cpp</a>.</p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 50</span> {</div>
|
|
<div class="line"><span class="lineno"> 51</span> std::vector<int32_t> res; </div>
|
|
<div class="line"><span class="lineno"> 52</span> <span class="keywordtype">size_t</span> f_index = 0; </div>
|
|
<div class="line"><span class="lineno"> 53</span> <span class="keywordtype">size_t</span> s_index = 0; </div>
|
|
<div class="line"><span class="lineno"> 54</span> <span class="keywordtype">size_t</span> f_length = first.size(); </div>
|
|
<div class="line"><span class="lineno"> 55</span> <span class="keywordtype">size_t</span> s_length = second.size(); </div>
|
|
<div class="line"><span class="lineno"> 56</span> int32_t next = 0; </div>
|
|
<div class="line"><span class="lineno"> 57</span> </div>
|
|
<div class="line"><span class="lineno"> 58</span> <span class="keywordflow">while</span> (f_index < f_length && s_index < s_length) {</div>
|
|
<div class="line"><span class="lineno"> 59</span> <span class="keywordflow">if</span> (first[f_index] < second[s_index]) {</div>
|
|
<div class="line"><span class="lineno"> 60</span> next = first[f_index]; </div>
|
|
<div class="line"><span class="lineno"> 61</span> f_index++; </div>
|
|
<div class="line"><span class="lineno"> 62</span> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (first[f_index] > second[s_index]) {</div>
|
|
<div class="line"><span class="lineno"> 63</span> next = second[s_index]; </div>
|
|
<div class="line"><span class="lineno"> 64</span> s_index++; </div>
|
|
<div class="line"><span class="lineno"> 65</span> } <span class="keywordflow">else</span> {</div>
|
|
<div class="line"><span class="lineno"> 66</span> next = first[f_index]; </div>
|
|
<div class="line"><span class="lineno"> 67</span> f_index++; </div>
|
|
<div class="line"><span class="lineno"> 68</span> s_index++; </div>
|
|
<div class="line"><span class="lineno"> 69</span> }</div>
|
|
<div class="line"><span class="lineno"> 70</span> <span class="keywordflow">if</span> ((res.size() == 0) || (next != res.back())) {</div>
|
|
<div class="line"><span class="lineno"> 71</span> res.push_back(next); </div>
|
|
<div class="line"><span class="lineno"> 72</span> }</div>
|
|
<div class="line"><span class="lineno"> 73</span> }</div>
|
|
<div class="line"><span class="lineno"> 74</span> <span class="keywordflow">while</span> (f_index < f_length) {</div>
|
|
<div class="line"><span class="lineno"> 75</span> next = first[f_index]; </div>
|
|
<div class="line"><span class="lineno"> 76</span> <span class="keywordflow">if</span> ((res.size() == 0) || (next != res.back())) {</div>
|
|
<div class="line"><span class="lineno"> 77</span> res.push_back(next); </div>
|
|
<div class="line"><span class="lineno"> 78</span> }</div>
|
|
<div class="line"><span class="lineno"> 79</span> f_index++;</div>
|
|
<div class="line"><span class="lineno"> 80</span> }</div>
|
|
<div class="line"><span class="lineno"> 81</span> <span class="keywordflow">while</span> (s_index < s_length) {</div>
|
|
<div class="line"><span class="lineno"> 82</span> next = second[s_index]; </div>
|
|
<div class="line"><span class="lineno"> 83</span> <span class="keywordflow">if</span> ((res.size() == 0) || (next != res.back())) {</div>
|
|
<div class="line"><span class="lineno"> 84</span> res.push_back(next); </div>
|
|
<div class="line"><span class="lineno"> 85</span> }</div>
|
|
<div class="line"><span class="lineno"> 86</span> s_index++;</div>
|
|
<div class="line"><span class="lineno"> 87</span> }</div>
|
|
<div class="line"><span class="lineno"> 88</span> <span class="keywordflow">return</span> res;</div>
|
|
<div class="line"><span class="lineno"> 89</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a6109193567a5b7e36a27f2b4865fce20" name="a6109193567a5b7e36a27f2b4865fce20"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a6109193567a5b7e36a27f2b4865fce20">◆ </a></span>print()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void operations_on_datastructures::print </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const std::vector< int32_t > &</td> <td class="paramname"><span class="paramname"><em>array</em></span></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Prints the values of a vector sequentially, ending with a newline character. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">array</td><td>Reference to the array to be printed </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
|
<p>Print each value in the array</p>
|
|
<p>Print newline</p>
|
|
<p>Print each value in the array</p>
|
|
<p>Print newline</p>
|
|
<p>Print each value in the array</p>
|
|
<p>Print newline</p>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../d9/d14/array__left__rotation_8cpp_source.html#l00029">29</a> of file <a class="el" href="../../d9/d14/array__left__rotation_8cpp_source.html">array_left_rotation.cpp</a>.</p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 29</span> {</div>
|
|
<div class="line"><span class="lineno"> 30</span> <span class="keywordflow">for</span> (int32_t i : array) {</div>
|
|
<div class="line"><span class="lineno"> 31</span> std::cout << i << <span class="stringliteral">" "</span>; </div>
|
|
<div class="line"><span class="lineno"> 32</span> }</div>
|
|
<div class="line"><span class="lineno"> 33</span> std::cout << <span class="stringliteral">"\n"</span>; </div>
|
|
<div class="line"><span class="lineno"> 34</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="afce39cf843989a39811a49ebe29dd6d8" name="afce39cf843989a39811a49ebe29dd6d8"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#afce39cf843989a39811a49ebe29dd6d8">◆ </a></span>shift_left()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">std::vector< int32_t > operations_on_datastructures::shift_left </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const std::vector< int32_t > &</td> <td class="paramname"><span class="paramname"><em>array</em></span>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">size_t</td> <td class="paramname"><span class="paramname"><em>shift</em></span> )</td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Shifts the given vector to the left by the shift amount and returns a new vector with the result. The original vector is not mutated. </p>
|
|
<p>Shifts the values of the vector, by creating a new vector and adding values from the shift index to the end, then appending the rest of the elements from the start of the vector. </p><dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">array</td><td>A reference to the input std::vector </td></tr>
|
|
<tr><td class="paramname">shift</td><td>The amount to be shifted to the left </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>A std::vector with the shifted values </dd></dl>
|
|
<p>< We got an invalid shift, return empty array</p>
|
|
<p>< Result array</p>
|
|
<p>< Add values after the shift index</p>
|
|
<p>< Add the values from the start</p>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../d9/d14/array__left__rotation_8cpp_source.html#l00046">46</a> of file <a class="el" href="../../d9/d14/array__left__rotation_8cpp_source.html">array_left_rotation.cpp</a>.</p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 47</span> {</div>
|
|
<div class="line"><span class="lineno"> 48</span> <span class="keywordflow">if</span> (array.size() <= shift) {</div>
|
|
<div class="line"><span class="lineno"> 49</span> <span class="keywordflow">return</span> {}; </div>
|
|
<div class="line"><span class="lineno"> 50</span> }</div>
|
|
<div class="line"><span class="lineno"> 51</span> std::vector<int32_t> res(array.size()); </div>
|
|
<div class="line"><span class="lineno"> 52</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = shift; i < array.size(); i++) {</div>
|
|
<div class="line"><span class="lineno"> 53</span> res[i - shift] = array[i]; </div>
|
|
<div class="line"><span class="lineno"> 54</span> }</div>
|
|
<div class="line"><span class="lineno"> 55</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < shift; i++) {</div>
|
|
<div class="line"><span class="lineno"> 56</span> res[array.size() - shift + i] =</div>
|
|
<div class="line"><span class="lineno"> 57</span> array[i]; </div>
|
|
<div class="line"><span class="lineno"> 58</span> }</div>
|
|
<div class="line"><span class="lineno"> 59</span> <span class="keywordflow">return</span> res;</div>
|
|
<div class="line"><span class="lineno"> 60</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a1bfb8711f49e591eb168ccaa3df6fb86" name="a1bfb8711f49e591eb168ccaa3df6fb86"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a1bfb8711f49e591eb168ccaa3df6fb86">◆ </a></span>shift_right()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">std::vector< int32_t > operations_on_datastructures::shift_right </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const std::vector< int32_t > &</td> <td class="paramname"><span class="paramname"><em>array</em></span>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">size_t</td> <td class="paramname"><span class="paramname"><em>shift</em></span> )</td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Shifts the given vector to the right by the shift amount and returns a new vector with the result. The original vector is not mutated. </p>
|
|
<p>Shifts the values of the vector, by creating a new vector and adding values from the shift index to the end, then appending the rest of the elements to the start of the vector. </p><dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">array</td><td>A reference to the input std::vector </td></tr>
|
|
<tr><td class="paramname">shift</td><td>The amount to be shifted to the right </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>A std::vector with the shifted values </dd></dl>
|
|
<p>< We got an invalid shift, return empty array</p>
|
|
<p>< Result array</p>
|
|
<p>< Add values after the shift index</p>
|
|
<p>< Add the values from the start</p>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="../../d6/d57/array__right__rotation_8cpp_source.html#l00047">47</a> of file <a class="el" href="../../d6/d57/array__right__rotation_8cpp_source.html">array_right_rotation.cpp</a>.</p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 48</span> {</div>
|
|
<div class="line"><span class="lineno"> 49</span> <span class="keywordflow">if</span> (array.size() <= shift) {</div>
|
|
<div class="line"><span class="lineno"> 50</span> <span class="keywordflow">return</span> {}; </div>
|
|
<div class="line"><span class="lineno"> 51</span> }</div>
|
|
<div class="line"><span class="lineno"> 52</span> std::vector<int32_t> res(array.size()); </div>
|
|
<div class="line"><span class="lineno"> 53</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = shift; i < array.size(); i++) {</div>
|
|
<div class="line"><span class="lineno"> 54</span> res[i] = array[i - shift]; </div>
|
|
<div class="line"><span class="lineno"> 55</span> }</div>
|
|
<div class="line"><span class="lineno"> 56</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < shift; i++) {</div>
|
|
<div class="line"><span class="lineno"> 57</span> res[i] =</div>
|
|
<div class="line"><span class="lineno"> 58</span> array[array.size() - shift + i]; </div>
|
|
<div class="line"><span class="lineno"> 59</span> }</div>
|
|
<div class="line"><span class="lineno"> 60</span> <span class="keywordflow">return</span> res;</div>
|
|
<div class="line"><span class="lineno"> 61</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<div id="page-nav" class="page-nav-panel">
|
|
<div id="page-nav-resize-handle"></div>
|
|
<div id="page-nav-tree">
|
|
<div id="page-nav-contents">
|
|
</div><!-- page-nav-contents -->
|
|
</div><!-- page-nav-tree -->
|
|
</div><!-- page-nav -->
|
|
</div><!-- container -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a href="../../da/d6d/namespaceoperations__on__datastructures.html">operations_on_datastructures</a></li>
|
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.14.0 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|