Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
715038a
modified js/article
aisha0320 Feb 6, 2025
796625c
Merge branch 'torqbit:main' into main
aisha0320 Feb 6, 2025
f8823bb
adding contents in portfolio web
aisha0320 Feb 8, 2025
c3454dd
adding react in branch
aisha0320 Feb 8, 2025
e036621
adding tree in datastructures
aisha0320 Feb 8, 2025
0c7e350
modified cookies
aisha0320 Feb 10, 2025
1528c26
copying git from main
aisha0320 Feb 10, 2025
aeaf63d
copying modified raect
aisha0320 Feb 10, 2025
4f8f9c8
Merge pull request #19 from aisha-agarwal00/portfolio-web
amezng Feb 11, 2025
0ab89b4
added and deleted all the changes
aisha0320 Feb 11, 2025
b5131ce
Merge branch 'aisha' into portfolio-web
amezng Feb 11, 2025
cb2f4ce
Merge pull request #20 from aisha-agarwal00/portfolio-web-dev
amezng Feb 11, 2025
86ecfd0
added portfolio web
aisha0320 Feb 11, 2025
b165370
Merge branch 'aisha' into portfolio-web-dev
aisha0320 Feb 11, 2025
7d8f488
added changes
aisha0320 Feb 16, 2025
621c583
added modified files
aisha0320 Feb 16, 2025
1b5184d
restructured
aisha0320 Feb 16, 2025
5efc524
all the changes with queue and stack
aisha0320 Feb 18, 2025
2feea9c
assingnments
aisha0320 Feb 19, 2025
5261061
completed assignment
aisha0320 Feb 19, 2025
683dfb7
completed assignment
aisha0320 Feb 19, 2025
09c68df
added assigmnet
aisha0320 Feb 21, 2025
3baa1e1
Merge branch 'aisha' into react-project
amezng Feb 22, 2025
490589b
Assignment completed
aisha0320 Feb 26, 2025
b8e8f70
index completed
aisha0320 Feb 27, 2025
504af3f
modified flies
aisha0320 Mar 1, 2025
d7c0e30
added assignment
aisha0320 Mar 3, 2025
596022b
added new files
aisha0320 Mar 4, 2025
b256293
5th march assignment
aisha0320 Mar 5, 2025
e019dc9
all the modified filed added
aisha0320 Mar 13, 2025
8184791
all the modified filed added
aisha0320 Mar 16, 2025
3c656ae
setTime assignment added
aisha0320 Mar 20, 2025
a13bf2a
setInterval assignment added
aisha0320 Mar 22, 2025
f3870d3
assignment added
aisha0320 Mar 25, 2025
6a5af45
adding assignment for useRef
aisha0320 Mar 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 44 additions & 18 deletions 03-javascript/datastructures/queue/queue.mjs
Original file line number Diff line number Diff line change
@@ -1,34 +1,67 @@
import { Stack } from "../stack/stack.mjs";
// Queue class for basic queue operations
class Queue {

export class Queue {
constructor() {
this.items = [];
}

enqueue(element) {
// Implement enqueue operation
return this.items.push(element)
}

dequeue() {
// Implement dequeue operation
return this.items.shift()
}

peek() {
// Implement peek operation
if (this.items.length != 0){
return this.items[0]
}
else{
return 'Queue is empty'
}
}

isEmpty() {
// Implement isEmpty operation
if (this.items.length == 0){
return true
}
else{
return false
}
}
}

// Function to reverse a queue
function reverseQueue(queue) {
// Implement reverseQueue function
export function reverseQueue(queue) {
const stack = new Stack();
const obj = new Queue()
for(let i in queue){
obj.enqueue(queue[i])
}
while (!obj.isEmpty()) {
stack.push(obj.dequeue());
}
const reversed = [];
while (!stack.isEmpty()) {
reversed.push(stack.pop());
}
return reversed;
}

// Function to check if a string is a palindrome using a queue
function isPalindrome(input) {
// Implement isPalindrome function
export function isPalindrome(input) {
const strSplit = [...input]
console.log(typeof(strSplit))
console.log(typeof(reverseQueue(input)))
console.log(strSplit)
console.log(reverseQueue(input))
if (strSplit == reverseQueue(input)){
return 'it is a palindrone'
}
else{
return 'it is not a palindrone'
}
}

// CircularQueue class for implementing a circular queue
Expand Down Expand Up @@ -66,11 +99,4 @@ function simulateQueue(customers, serviceTime) {
// Implement simulateQueue function
}

// Exporting the classes and functions for use
export default {
Queue,
reverseQueue,
isPalindrome,
CircularQueue,
simulateQueue,
};
// Exporting the classes and functions for use
11 changes: 11 additions & 0 deletions 03-javascript/datastructures/queue/scratch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { reverseQueue } from "./queue.mjs";
import { Queue } from "./queue.mjs";
import { isPalindrome } from "./queue.mjs";
const input = [1,2,3,4,5,6,7]
console.log(input)
console.log(reverseQueue(input))

console.log(isPalindrome('aisha'))
console.log(isPalindrome('racecar'))
console.log(isPalindrome('madam'))
console.log(isPalindrome('level'))
8 changes: 8 additions & 0 deletions 03-javascript/datastructures/stack/scratch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { reverseString } from "./stack.mjs";
import { isBalanced } from "./stack.mjs";
import { sortStack } from "./stack.mjs";
//console.log(reverseString("harsh"))
//console.log(typeof(reverseString("harsh")))
//console.log(isBalanced('{)'))
const input = [5,8,7,9,3,4]
console.log(sortStack(input))
72 changes: 0 additions & 72 deletions 03-javascript/datastructures/stack/stack.js

This file was deleted.

125 changes: 125 additions & 0 deletions 03-javascript/datastructures/stack/stack.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Stack class for basic stack operations
export class Stack {
constructor() {
this.items = [];
}

push(element) {
this.items.push(element)
}

pop() {
if (this.items.length != 0){
return this.items.pop()
}
else{
return 'Stack is empty'
}
}

peek() {
if (this.items.length != 0){
return this.items[this.items.length -1]
}
else{
return 'Stack is empty'
}
}

isEmpty() {
return this.items.length === 0
}
}
//const stack = new Stack()

// Function to reverse a string using a stack
export function reverseString(input) {
const stack = new Stack()

for(let i in input){
stack.push(input[i])
}
const reverse = []
while (!stack.isEmpty()){
reverse.push(stack.pop())
}
return reverse.join("")
}

// Function to check if parentheses are balanced
export function isBalanced(input) {
if (input == reverseString(input)){
return true
}
else{
return false
}
}
// not able to do this one. still trying

// MinStack class to support retrieving the minimum element
class MinStack extends Stack {
constructor() {
super();
this.minStack = []
}

push(element) {
super.push(element)
if (this.minStack.length === 0){
this.minStack.push(element)
}
else{
if (element <= this.minStack[this.minStack.length -1]){
this.minStack.push(element)
}
else{
this.minStack.push(this.minStack[this.minStack.length -1])
}
}
}

pop() {
if (this.length == 0){
return 'stack and Minstack is empty'
}
else{
super.pop()
this.minStack.pop()
}
}

getMin() {
if (this.minStack.length === 0){
return 'minstack is empty'
}
else{
return this.minStack[this.minStack.length -1]
}
}
}

// Function to evaluate a postfix expression
function evaluatePostfix(expression) {
// Implement evaluatePostfix function
}

// Function to sort a stack using only stack operations
export function sortStack(stack) {
const obj = new Stack();
for (let i in stack) {
obj.push(stack[i]);
}
const auxiliaryStack = [];
while (!obj.isEmpty()) {
let temp = obj.pop();
while (auxiliaryStack.length > 0 && auxiliaryStack[auxiliaryStack.length - 1] > temp) {
let moved = auxiliaryStack.pop();
obj.push(moved);
}
auxiliaryStack.push(temp);
}
return auxiliaryStack;
}

// Exporting the functions and classes for use
11 changes: 10 additions & 1 deletion 03-javascript/datastructures/tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,55 +74,64 @@ In this example:
## Practice Assignments 🎯

### Assignment 1: Tree Height Calculator

**Difficulty: Easy**

**Objective:** Create a function to calculate the height of a binary tree.

**Instructions:**

- Implement a function `getTreeHeight(root)` that takes the root node as input
- Return the maximum height (depth) of the tree
- Return 0 for an empty tree

### Assignment 2: Node Counter

**Difficulty: Easy**

**Objective:** Count the total number of nodes in a binary tree.

**Instructions:**

- Create a function `countNodes(root)` that takes the root node as input
- Count and return the total number of nodes in the tree
- Include both leaf nodes and internal nodes in the count

### Assignment 3: Leaf Node Finder

**Difficulty: Medium**

**Objective:** Find and print all leaf nodes in a binary tree.

**Instructions:**

- Implement a function `findLeafNodes(root)` that takes the root node as input
- Return an array containing all leaf nodes (nodes with no children)
- Maintain the order of leaves from left to right

### Assignment 4: Level Order Traversal

**Difficulty: Medium**

**Objective:** Print nodes level by level, from top to bottom.

**Instructions:**

- Create a function `levelOrderTraversal(root)` that takes the root node as input
- Print nodes at each level on a new line
- Use a queue to manage the level-by-level traversal

### Assignment 5: Tree Mirror

**Difficulty: Medium**

**Objective:** Create a mirror image of a binary tree.

**Instructions:**

- Implement a function `mirrorTree(root)` that takes the root node as input
- Swap left and right children of all nodes
- Return the root node of the mirrored tree
- The original tree structure should be modified in place

Each assignment builds upon the basic binary tree concepts and helps understand different tree operations and traversal techniques.

Loading