diff --git a/Algorithms/sorting/Python/CombSort.py b/Algorithms/sorting/Python/CombSort.py new file mode 100644 index 0000000..f9ddc43 Binary files /dev/null and b/Algorithms/sorting/Python/CombSort.py differ diff --git a/Algorithms/sorting/Python/CountSort.py b/Algorithms/sorting/Python/CountSort.py new file mode 100644 index 0000000..4e9571a Binary files /dev/null and b/Algorithms/sorting/Python/CountSort.py differ diff --git a/Algorithms/sorting/Python/CycleSort.py b/Algorithms/sorting/Python/CycleSort.py new file mode 100644 index 0000000..dae43f1 Binary files /dev/null and b/Algorithms/sorting/Python/CycleSort.py differ diff --git a/Algorithms/sorting/Python/MergeSort1.py b/Algorithms/sorting/Python/MergeSort1.py new file mode 100644 index 0000000..c0bfb5d Binary files /dev/null and b/Algorithms/sorting/Python/MergeSort1.py differ diff --git a/Algorithms/sorting/Python/RadixSort.py b/Algorithms/sorting/Python/RadixSort.py new file mode 100644 index 0000000..7283080 Binary files /dev/null and b/Algorithms/sorting/Python/RadixSort.py differ diff --git a/Data Structures/Hash Map/hashmap.cpp b/Data Structures/Hash Map/hashmap.cpp new file mode 100644 index 0000000..0e7ab04 --- /dev/null +++ b/Data Structures/Hash Map/hashmap.cpp @@ -0,0 +1,82 @@ +#include +#include +#include + +using namespace std; + +int main() +{ + + // empty map container + map gquiz1; + + // insert elements in random order + gquiz1.insert(pair(1, 40)); + gquiz1.insert(pair(2, 30)); + gquiz1.insert(pair(3, 60)); + gquiz1.insert(pair(4, 20)); + gquiz1.insert(pair(5, 50)); + gquiz1.insert(pair(6, 50)); + gquiz1.insert(pair(7, 10)); + + // printing map gquiz1 + map::iterator itr; + cout << "\nThe map gquiz1 is : \n"; + cout << "\tKEY\tELEMENT\n"; + for (itr = gquiz1.begin(); itr != gquiz1.end(); ++itr) { + cout << '\t' << itr->first + << '\t' << itr->second << '\n'; + } + cout << endl; + + // assigning the elements from gquiz1 to gquiz2 + map gquiz2(gquiz1.begin(), gquiz1.end()); + + // print all elements of the map gquiz2 + cout << "\nThe map gquiz2 after" + << " assign from gquiz1 is : \n"; + cout << "\tKEY\tELEMENT\n"; + for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) { + cout << '\t' << itr->first + << '\t' << itr->second << '\n'; + } + cout << endl; + + // remove all elements up to + // element with key=3 in gquiz2 + cout << "\ngquiz2 after removal of" + " elements less than key=3 : \n"; + cout << "\tKEY\tELEMENT\n"; + gquiz2.erase(gquiz2.begin(), gquiz2.find(3)); + for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) { + cout << '\t' << itr->first + << '\t' << itr->second << '\n'; + } + + // remove all elements with key = 4 + int num; + num = gquiz2.erase(4); + cout << "\ngquiz2.erase(4) : "; + cout << num << " removed \n"; + cout << "\tKEY\tELEMENT\n"; + for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) { + cout << '\t' << itr->first + << '\t' << itr->second << '\n'; + } + + cout << endl; + + // lower bound and upper bound for map gquiz1 key = 5 + cout << "gquiz1.lower_bound(5) : " + << "\tKEY = "; + cout << gquiz1.lower_bound(5)->first << '\t'; + cout << "\tELEMENT = " + << gquiz1.lower_bound(5)->second << endl; + cout << "gquiz1.upper_bound(5) : " + << "\tKEY = "; + cout << gquiz1.upper_bound(5)->first << '\t'; + cout << "\tELEMENT = " + << gquiz1.upper_bound(5)->second << endl; + + return 0; +} \ No newline at end of file diff --git a/Data Structures/Hash Map/hashmap.java b/Data Structures/Hash Map/hashmap.java new file mode 100644 index 0000000..2ea95b9 --- /dev/null +++ b/Data Structures/Hash Map/hashmap.java @@ -0,0 +1,44 @@ +// Java program to illustrate +// Java.util.HashMap + +import java.util.HashMap; +import java.util.Map; + +public class GFG { + public static void main(String[] args) + { + + HashMap map + = new HashMap<>(); + + print(map); + map.put("vishal", 10); + map.put("sachin", 30); + map.put("vaibhav", 20); + + System.out.println("Size of map is:- " + + map.size()); + + print(map); + if (map.containsKey("vishal")) { + Integer a = map.get("vishal"); + System.out.println("value for key" + + " \"vishal\" is:- " + + a); + } + + map.clear(); + print(map); + } + + public static void print(Map map) + { + if (map.isEmpty()) { + System.out.println("map is empty"); + } + + else { + System.out.println(map); + } + } +}