This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int findSubString(string s, string sub, const string &S, int pos, int cur) { | |
| if (sub.empty()) | |
| return pos; | |
| else if (s.empty()) | |
| return -1; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| vector<vector<bool>> board; | |
| vector<bool> columnEmpty, leftDiagEmpty, rightDiagEmpty; | |
| bool isSafe(int r, int c, int n) { | |
| return columnEmpty[c] && leftDiagEmpty[r + c] && rightDiagEmpty[n - 1 + r - c]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <algorithm> | |
| using namespace std; | |
| template <class T> | |
| struct Node { | |
| T key; | |
| Node *next; | |
| Node() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| void reverse_string(string &sentence) { | |
| for (int i = 0; i < sentence.size() / 2; i++) | |
| swap(sentence[i], sentence[sentence.size() - 1 - i]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| template <class T> | |
| void bubble_sort(vector<T> &input_array) { | |
| for (int i = input_array.size() - 2; i >= 0; i--) | |
| for (int j = 0; j <= i; j++) | |
| if (input_array[j] > input_array[j + 1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| template <class T> | |
| int partition_array(int low, int high, vector<T> &input_array) { | |
| int i = low; | |
| for (int j = low; j < high; j++) | |
| if (input_array[j] <= input_array[high]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| template<class T> | |
| struct Results { | |
| int low, high; | |
| T sum; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| template <class T> | |
| void merge_two_sorted_arrays(int low, int high, int mid, vector<T> &input_array) { | |
| vector<T> partial_array; | |
| int m = low, n = mid + 1; | |
| while (m <= mid && n <= high) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| `define INPUTSIZE 32 //hard-coded: don't change | |
| `define FINALADDER 2 //choose from CSA, CLA and prefix CLA (need to include corresponding functions) | |
| module Array_Reduction_Multiplier_64b(X,Y,Z); | |
| input [`INPUTSIZE - 1:0] X; | |
| input [`INPUTSIZE - 1:0] Y; | |
| output [`INPUTSIZE * 2 - 1:0] Z; | |
| wire [(`INPUTSIZE * 2) * (`INPUTSIZE * 2 - 1) - 1:0] addend; | |
| wire [`INPUTSIZE * `INPUTSIZE - 1:0] bit_and; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| `define INPUTSIZE 32 //set the input size n | |
| module Carry_Save_Multiplier(X,Y,Z); | |
| input [`INPUTSIZE - 1:0] X; | |
| input [`INPUTSIZE - 1:0] Y; | |
| output [`INPUTSIZE * 2 - 1:0] Z; | |
| wire [`INPUTSIZE * `INPUTSIZE - 1:0] partial_sum; | |
| wire [`INPUTSIZE * (`INPUTSIZE - 1) - 1:0] and_out; |
NewerOlder