Line and Word Counter using Hashing
9 months ago#include <iostream>
#include <unordered_map>
#include <sstream>
#include <string>
using namespace std;
int main() {
unordered_map<string, int> lineHash; // Hash map to store line -> frequency
string line;
int totalLines = 0, totalWords = 0;
BFS and DFS Traversal
9 months ago#include <iostream>
#include <vector>
#include <queue>
using namespace std;
// ---------------------- BFS FUNCTION ----------------------
void bfs(int start, vector<vector<int>>& adj, int n) {
vector<bool> visited(n, false);
queue<int> q;
quick sort
9 months ago#include <iostream>
using namespace std;
int partition(int arr[], int low, int high) {
int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++) {
if (arr[j] < pivot) {
i++;
Untitled
9 months ago#include <iostream>
using namespace std;
void merge(int arr[], int l, int m, int r) {
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (int i = 0; i < n1; i++)
shell sort
9 months ago#include <iostream>
using namespace std;
void shellSort(int arr[], int n) {
for (int gap = n / 2; gap > 0; gap /= 2) {
for (int i = gap; i < n; i++) {
int temp = arr[i];
int j = i;
while (j >= gap && arr[j - gap] > temp) {
arr[j] = arr[j - gap];
insertion_sort
9 months ago#include <iostream>
using namespace std;
void insertionSort(int arr[], int n) {
for (int i = 1; i < n; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j--;
selection_sort.cpp
9 months ago#include <iostream>
using namespace std;
void selectionSort(int arr[], int n) {
for (int i = 0; i < n - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < n; j++) {
if (arr[j] < arr[minIndex])
minIndex = j;
}
binary search tree
9 months ago#include <iostream>
using namespace std;
// Structure for a BST node
struct Node {
int data;
Node* left;
Node* right;
};
recursive binary search in sorted array
9 months ago#include <iostream>
using namespace std;
// Recursive Binary Search Function
int binarySearch(int arr[], int low, int high, int key) {
if (low > high)
return -1; // Element not found
int mid = (low + high) / 2;
Tina love cookies
9 months ago#include <iostream>
using namespace std;
// Node structure for Linked List
struct Node {
int data;
Node* next;
};
// Function to insert a node in sorted order
queue using linked list
9 months ago#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
};
class Queue {
Node* front;
queue using array
9 months ago#include <iostream>
using namespace std;
class Queue {
int arr[10];
int front, rear;
public:
Queue() { front = rear = -1; }
void enqueue(int val) {
stack using linked list
9 months ago#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
};
class Stack {
Node* top;
stack using array
9 months ago#include <iostream>
using namespace std;
class Stack {
int arr[10];
int top;
public:
Stack() { top = -1; }
void push(int val) {
reading and writing of polynomial
9 months ago#include <iostream>
using namespace std;
int main() {
int deg1, deg2;
cout << "Enter degree of first polynomial: ";
cin >> deg1;
int p1[20];
cout << "Enter coefficients from highest degree to constant term:\n";
for (int i = 0; i <= deg1; i++)
infix to postfix
9 months ago#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;
int precedence(char c) {
if (c == '+' || c == '-') return 1;
if (c == '*' || c == '/') return 2;
if (c == '^') return 3;
return 0;