This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
struct stack { | |
int * keys; | |
int max_size; | |
int peek; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, key): | |
self.key = key | |
self.next = None | |
class Stack: | |
def __init__(self): | |
self.peek = None | |
def is_empty(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
struct node { | |
int key; | |
struct node * next; | |
}; | |
//Function prototpye or method on stack. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, key): | |
self.key = key | |
self.next = None | |
self.prev = None | |
class CircularLinkedList: | |
def __init__(self): | |
self.head = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, key): | |
self.key = key | |
self.next = None | |
self.prev = None | |
class DoublyLinkedList: | |
def __init__(self): | |
self.head = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, key): | |
self.key = key | |
self.next = None | |
class LinkedList: | |
def __init__(self): | |
self.head = None |
OlderNewer