Skip to content

Instantly share code, notes, and snippets.

View cs-fedy's full-sized avatar
🎯
Focusing

Fedi Abdouli cs-fedy

🎯
Focusing
View GitHub Profile
@cs-fedy
cs-fedy / ListStack.py
Created August 4, 2020 06:41
stack implementation using list in python.
class ListStack:
def __init__(self):
self.stack = []
def is_empty(self):
return not self.stack
def get_peek(self):
assert(not self.is_empty())
return self.stack[-1]
@cs-fedy
cs-fedy / ListStack.c
Last active August 6, 2020 08:43
Array Implementation of STACK (abstract data type) in C programming.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
struct stack {
int * keys;
int max_size;
int peek;
};
@cs-fedy
cs-fedy / LinkedListStack.py
Created August 4, 2020 07:33
Implement a stack using singly linked list.
class Node:
def __init__(self, key):
self.key = key
self.next = None
class Stack:
def __init__(self):
self.peek = None
def is_empty(self):
@cs-fedy
cs-fedy / LinkedListStack.c
Created August 4, 2020 07:51
Implement a stack using singly linked list.Implement a stack using singly linked list c programming.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
struct node {
int key;
struct node * next;
};
//Function prototpye or method on stack.
@cs-fedy
cs-fedy / evaluate_exp.c
Created August 6, 2020 10:25
Write code to efficiently evaluate given postfix expression.
// Write code to efficiently evaluate given postfix expression.
int evaluate_exp(char exp[], stck * st) {
int index = 0, x, y;
char ch;
while (exp[index] != '\0') {
ch = exp[index];
if (ch >= '0' && ch <= '9') {
push(ch - '0', st);
}
else {
@cs-fedy
cs-fedy / is_duplicated.c
Created August 6, 2020 10:26
Given a balanced expression that can contain opening and closing parenthesis, check if the expression contains any duplicate parenthesis or not.
// Given a balanced expression that can contain opening and closing parenthesis,
// check if the expression contains any duplicate parenthesis or not.
unsigned is_duplicated(char str[], stck * st) {
int index = 0;
char ch;
while (str[index] != '\0') {
ch = str[index];
if (ch != ')')
push(ch, st);
else {
@cs-fedy
cs-fedy / is_balanced.c
Created August 6, 2020 10:26
Given a string containing opening and closing braces, check if it represents a balanced expression or not.
// Given a string containing opening and closing braces,
// check if it represents a balanced expression or not.
unsigned is_balanced(char str[], stck * st) {
int index = 0;
char top, ch;
while(str[index] != '\0') {
ch = str[index];
if (ch == '{' || ch == '(' || ch == '[') {
push(ch, st);
}
@cs-fedy
cs-fedy / CircularLinkedList.py
Last active August 8, 2020 10:53
Implementing circular linked-list in Python programming language.
class Node:
def __init__(self, key):
self.key = key
self.next = None
self.prev = None
class CircularLinkedList:
def __init__(self):
self.head = None
@cs-fedy
cs-fedy / DoublyLinkedList.py
Created August 8, 2020 10:52
Implementing doubly linked-list in Python programming language.
class Node:
def __init__(self, key):
self.key = key
self.next = None
self.prev = None
class DoublyLinkedList:
def __init__(self):
self.head = None
@cs-fedy
cs-fedy / SinglyLinkedList.py
Created August 8, 2020 10:53
Implementing singlyr linked-list in Python programming language.
class Node:
def __init__(self, key):
self.key = key
self.next = None
class LinkedList:
def __init__(self):
self.head = None