Skip to content

Commit

Permalink
Cleanup directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoranPandovski committed Sep 27, 2021
1 parent 3e22c97 commit 2551bed
Show file tree
Hide file tree
Showing 17 changed files with 841 additions and 0 deletions.
26 changes: 26 additions & 0 deletions data_structures/Linked_list/LinkedList/Javascript/linked_list.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.node-list{
margin-top:10px;
}
.node{
display:inline-block;
}
.node span{
display:inline-block;
border:1px solid #ccc;
border-radius:100%;
padding:8px;
transition:1s all;
}
.node:before{
content:'';
display:inline-block;
width:50px;
height:0px;
margin-bottom:4px;
line-height:1px;
border:1px solid #333;
border-width:1px 0 0;
}
.zoom{
transform:scale(2)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
<input type=text class="value" placeholder='Value' name="value"/>
<input type=submit class="js-submit" value="Add"/>
<input type=submit class="js-remove" value="Remove"/>
<input type=submit class="js-find" value="Find"/>
</div>


<div class="node-list"></div>
130 changes: 130 additions & 0 deletions data_structures/Linked_list/LinkedList/Javascript/linked_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
var Node = function(data){
this.data=data;
this.next=null;
}

var LinkedList = function(){
this.next=null
}

LinkedList.prototype.addNode = function(value){
var ref= this;
while(ref.next != null){
ref = ref.next
};
ref.next = new Node(value)
}

LinkedList.prototype.findNode = function(value){
var ref= this.next;
while(ref != null){
if(ref.data == value){
return ref
}
ref = ref.next
};

return null
}

LinkedList.prototype.removeNode = function(value){
var ref= this.next,
prev = this,
next = null;
while(ref != null){
if(ref.data == value){
next = ref.next;
prev.next = next;
return true;
}
prev = ref;
ref = ref.next;
};

return false
}

var ll =new LinkedList();

//ll.addNode(new Node(10));

var submit =document.getElementsByClassName('js-submit')[0];

var find =document.getElementsByClassName('js-find')[0];

var remove =document.getElementsByClassName('js-remove')[0];

var nodeList = document.getElementsByClassName('node-list')[0];

submit.addEventListener('click',function(e){
ll.addNode(document.getElementsByClassName('value')[0].value);
renderView();
})

remove.addEventListener('click',function(e){
ll.removeNode(document.getElementsByClassName('value')[0].value);
renderView();
})

find.addEventListener('click',function(e){
var value = document.getElementsByClassName('value')[0].value;
if(ll.findNode(value) != null){
_zoom(document.getElementsByClassName(value),true);
setTimeout(function(){
_zoom(document.getElementsByClassName(value),false);
},1500)
}

})

function _zoom(ref,flag){
if(flag) {
console.log(ref)
for (i in ref){
if(typeof ref[i] == 'object'){
ref[i].classList.add('zoom')
}
}
} else {
for (i in ref){
if(typeof ref[i] == 'object'){
ref[i].classList.remove('zoom')
}
}0
}
}
function renderView(){
var str = '',
ref = ll,
counter=0;
nodeList.innerHTML = '';
while(ref.next !== null){
nodeList.appendChild(createNode(ref.next.data,counter));
counter++;
ref = ref.next;
}

function createNode(value,counter){
var container = document.createElement('div'),
dataElement = document.createElement('span');

container.className="node";
dataElement.innerHTML = value;

dataElement.style.background = getColor(value,counter)
container.appendChild(dataElement);
dataElement.className=value;
return container
}
function getColor(value,counter){
value = 255 - Number(value)%255;
switch (value%3){
case 0:
return 'rgb('+value+','+value+',0)';
case 1:
return 'rgb('+value+',0,'+value+')';
default:
return 'rgb(0,'+value+','+value+')';
}
}
}
55 changes: 55 additions & 0 deletions data_structures/Stack/stack/C/Array_implementation_stack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* c program for the array implementation of stack */

#include <stdio.h>
#include <stdlib.h>

#define size 100
int stack[size], top = -1;

void push(int x){

if(top > size-1){

printf("StackOverflow");

}else{
stack[++top] = x;
printf("Element inserted:%d \n",x);
}

}
void pop(){
if(top < 0){
printf("StackUnderFlow");
}
else{
printf("Element deleted %d", stack[top]);
top--;
}

}
void prints(){
int i;
printf("Element of stack are:");
for(i=0; i<=top;i++){
printf("%d ",stack[i]);

}

}

int main(void){


push(1);
push(2);
push(3);
push(4);
push(5);
push(6);
push(7);
pop();
prints();

return 0;
}
46 changes: 46 additions & 0 deletions data_structures/Stack/stack/C/LINKED_STACK.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>

// LINKED_STACK

typedef struct node{
int info;
struct node *next;
}NODE;

typedef NODE * LINKED_STACK;

void create_stack(LINKED_STACK *p){
*p = NULL;
}

int isEmpty(LINKED_STACK p){
return (p == NULL);
}

void insert(LINKED_STACK *p, int info){
NODE *new_node;
new_node = (NODE *) malloc (sizeof(NODE));
if(!new_node){
puts("Memory FULL\n");
exit(1);
}
new_node->info = info;
new_node->next = *p;
*p = new_node;
}

void removeSTACK (LINKED_STACK *p){
NODE *aux = *p;

if(isEmpty(*p)){
puts("Stack is Empty\n");
exit(2);
}
(*p) = (*p)->next;
free(aux);
}



int main(){}
92 changes: 92 additions & 0 deletions data_structures/Stack/stack/JAVA/STACK.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import java.util.ArrayList;

/**
* @author avcbcoder last modified @29-Oct-2018 @4:39:00 PM Code Library - TODO
*/

/**
* <========================================= About Genric stack class =============================================>
*
* DESCRIPTION of all the methods in stack class --------------------------------------------------------------------
* 1.push(x) -> push x to the stack ---------------------------------------------------------------------------------
* 2.pop(x) -> pop x from the stack ---------------------------------------------------------------------------------
* 3.top(x) -> peeks the top of stack but doesn't removes -----------------------------------------------------------
* 4.display() -> prints all the elements in stack from top to bottom -----------------------------------------------
* 5.isEmpty() -> returns true if stack is empty --------------------------------------------------------------------
*/

/**
*/

public class STACK<T> {

/**
* For Debugging
*/
public static void main(String[] args) throws Exception {
STACK<Integer> st = new STACK<Integer>();
st.push(1);
st.push(10);
st.push(5);
st.push(8);
st.display();
System.out.println("Removed " + st.pop());
st.display();
}

protected ArrayList<T> data = new ArrayList<>();
protected int tos = -1;
protected T defaultValue = null;

public STACK() {
this(10);
}

public STACK(int initialCapacity) {
this.data = new ArrayList<>();
}

public void push(T value) throws Exception {
this.tos++;
if (this.tos < data.size())
data.set(this.tos, value);
else
data.add(value);
}

public T top() throws Exception {
if (tos == -1)
throw new Exception("stack is empty");
return data.get(this.tos);
}

public T pop() throws Exception {
if (tos == -1)
throw new Exception("stack is empty");
else {
T rv = this.data.get(this.tos);
this.data.set(this.tos, defaultValue);
this.tos--;
return (rv);
}
}

public int size() {
return this.tos + 1;
}

public boolean isEmpty() {
if (this.tos == -1)
return true;
return false;
}

public void display() {
System.out.println("---------------------------");
System.out.print("top-> ");
for (int i = this.tos; i >= 0; i--)
System.out.print(this.data.get(i) + " ");
System.out.print("<-bottom");
System.out.println("\n---------------------------");
}
}
32 changes: 32 additions & 0 deletions data_structures/Stack/stack/Python/stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'''This code is written MTH Junaidi github: Miranjunaidi on 26th Oct 2019 at 7:15 PM IST'''

#POP function removes the last element of the list
def pop(stack):
del stack[-1]
return stack
#push function adds a new number num to the list at the end.
def push(stack,num):
stack.append(num)
return stack
#print function prints all the element of the stack sequestially
def prints(stack):
for i in stack:
print(i,end = " ")
print("")
#This is where the main funtions start

print("\n welcome, a new empty stack is created. \n press index numbers to do the opertations \n")
stack = []
a=0
while a!=4:
print(" 1.push \n 2.pop \n 3.see the stack \n 4.quit")
a = int(input())
if a == 1:
num = int(input("Enter the number you want to push"))
push(stack, num)
elif a == 2:
pop(stack)
elif a==3:
prints(stack)
elif a>4 or a<0:
print("enter a valid operation")
Loading

0 comments on commit 2551bed

Please sign in to comment.