Skip to content

Commit

Permalink
Merge pull request #55 from bistakazi101/main
Browse files Browse the repository at this point in the history
circularQueue
  • Loading branch information
mrsamirr authored Oct 21, 2023
2 parents 9ca48b1 + b035e5c commit d6ee2bf
Show file tree
Hide file tree
Showing 13 changed files with 494 additions and 43 deletions.
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
1 change: 0 additions & 1 deletion C++/ReverseLinkedList.cpp

This file was deleted.

Binary file added C++/circularQueue
Binary file not shown.
86 changes: 86 additions & 0 deletions C++/circularQueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <iostream>
using namespace std;

const int MAX_SIZE = 5; // Maximum size of the queue

class CircularQueue {
private:
int front, rear;
int arr[MAX_SIZE];

public:
CircularQueue() {
front = rear = -1;
}

// check if the queue is empty
bool isEmpty() {
return (front == -1 && rear == -1);
}

// check if the queue is full
bool isFull() {
return (front == (rear + 1) % MAX_SIZE);
}

// enqueue an element
void enqueue(int value) {
if (isFull()) {
cout << "Queue is full. Cannot enqueue." << endl;
return;
}
if (isEmpty()) {
front = rear = 0; //
} else {
rear = (rear + 1) % MAX_SIZE; // Circular increment of rear
}
arr[rear] = value;
cout << value << " enqueued to the queue." << endl;
}

// dequeue an element
void dequeue() {
if (isEmpty()) {
cout << "Queue is empty. Cannot dequeue." << endl;
return;
}
cout << arr[front] << " dequeued from the queue." << endl;
if (front == rear) {
front = rear = -1;
} else {
front = (front + 1) % MAX_SIZE; // Circular increment of front
}
}

// display the elements of the queue
void display() {
if (isEmpty()) {
cout << "Queue is empty." << endl;
return;
}
cout << "Elements in the queue: ";
int i = front;
while (true) {
cout << arr[i] << " ";
if (i == rear)
break;
i = (i + 1) % MAX_SIZE; // Circular increment of index
}
cout << endl;
}
};

int main() {
CircularQueue queue;
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
queue.display();
queue.dequeue();
queue.display();
queue.enqueue(4);
queue.enqueue(5);
queue.display();
queue.enqueue(6); // This will show an error as the queue is full.
return 0;
}
Binary file added C++/reverseLinkedList
Binary file not shown.
78 changes: 78 additions & 0 deletions C++/reverseLinkedList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <iostream>

using namespace std;


class Node {
public:
int data;
Node* next;

Node(int val) {
data = val;
next = nullptr;
}
};


class LinkedList {
public:
Node* head;


LinkedList() {
head = nullptr;
}

// insert a new element at the beginning of the linked list.
void insert(int val) {
Node* newNode = new Node(val);
newNode->next = head;
head = newNode;
}

// display the linked list elements.
void display() {
Node* current = head;
while (current != nullptr) {
cout << current->data << " -> ";
current = current->next;
}
cout << "nullptr" << endl;
}

// reverse the linked list.
void reverse() {
Node* prev = nullptr;
Node* current = head;
Node* nextNode = nullptr;

// Traverse the list
while (current != nullptr) {
nextNode = current->next;
current->next = prev;
prev = current;
current = nextNode;
}

head = prev; // Set the new head.
}
};

int main() {
LinkedList list;
list.insert(1);
list.insert(2);
list.insert(3);
list.insert(4);

cout << "Original Linked List: ";
list.display();

list.reverse();

cout << "Reversed Linked List: ";
list.display();

return 0;
}
Binary file added C++/stackOperations
Binary file not shown.
55 changes: 55 additions & 0 deletions C++/stackOperations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iostream>
#include <vector>

using namespace std; // Add this line to use the std namespace

class Stack {
private:
vector<int> stack;

public:
void push(int value) {
stack.push_back(value);
}

void pop() {
if (!isEmpty()) {
stack.pop_back();
} else {
cout << "Stack is empty. Cannot pop." << endl;
}
}

int top() {
if (!isEmpty()) {
return stack.back();
} else {
cout << "Stack is empty. No top element." << endl;
return -1; // Return a default value indicating an empty stack.
}
}

bool isEmpty() {
return stack.empty();
}
};

int main() {
Stack myStack;

myStack.push(10);
myStack.push(20);
myStack.push(30);

cout << "Top element: " << myStack.top() << endl;

myStack.pop();
myStack.pop();

cout << "Top element after pops: " << myStack.top() << endl;

myStack.pop();
myStack.pop(); // Trying pop from an empty stack

return 0;
}
Binary file added CodeRich Website/images/hero-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions CodeRich Website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CodeRich Community</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<header class="header">
<nav class="navbar">
<h2 class="logo"><a href="#">CodeRich Community</a></h2>
<input type="checkbox" id="menu-toggle" />
<label for="menu-toggle" id="hamburger-btn">
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
<path d="M3 12h18M3 6h18M3 18h18" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
</label>
<ul class="links">
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
<div class="buttons">
<a href="#" class="signin">Sign In</a>
<a href="#" class="signup">Sign Up</a>
</div>
</nav>
</header>
<section class="hero-section">
<div class="hero">
<h2>E-Learning Platform</h2>
<p>
"Embark on an exciting programming journey to bring your ideas to life. Discover limitless possibilities as you master the art of coding and play a pivotal role in shaping our digital future."
</p>
<div class="buttons">
<a href="#" class="join">Join Now</a>
<a href="#" class="learn">Learn More</a>
</div>
</div>
<div class="img">
<img src="/CodeRich Website/images/hero-bg.png" alt="hero image" />
</div>
</section>
</body>
</html>
Loading

0 comments on commit d6ee2bf

Please sign in to comment.