This file contains 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
def sumnums(arr,sum): | |
anslist = [] | |
dict = {} | |
for each in arr: | |
if each not in dict: | |
dict[each] = 1 | |
else: | |
dict[each] += 1 | |
print(dict) | |
for each in dict: |
This file contains 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 <iostream> | |
#include <string> | |
#include <iomanip> | |
#include <fstream> | |
#include <vector> | |
using namespace std; | |
template<typename ItemType> | |
void Swap(ItemType& V1, ItemType& V2 ) | |
{ |
This file contains 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
public class StackOperations{ | |
int mystack[]; | |
int global_size; | |
int counter = 0; | |
int newcounter = 0; | |
int extensionstack[]; | |
public StackOperations(int size){ | |
this.mystack = new int[size]; //create a stack of size as mentioned while creating object |
This file contains 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
package Driver; | |
import howard.edu.ood.hw2.collections.ArrayQueue; | |
public class Main_Queue { | |
public static void main(String args[]){ | |
ArrayQueue myqueue = new ArrayQueue(10); | |
//to enqueue elements onto the stack | |
for (int i = 0; i<20;i++){ |
This file contains 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
'''The code is meant to skip adding the character "a" and any other character that comes after "a". For this, I check if string's [i th] index = a, and add 1 to index, so that new index will be able to skip the character coming after "a". But this does not seem to be happening. Why is it so ?''' | |
str1 = "abcde" | |
str2 = "" | |
for i in range(len(str1)): | |
if str1[i] == "a": | |
i +=1 | |
continue | |
else: | |
str2 += str1[i] |
This file contains 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
'''The code is meant to skip adding the character "a" and any other character that comes after "a". For this, I check if string's [i th] index = a, and add 1 to index, so that new index will be able to skip the character coming after "a". But this does not seem to be happening. Why is it so ?''' | |
str1 = "abcde" | |
str2 = "" | |
for i in range(len(str1)): | |
if str1[i] == "a": | |
i +=1 | |
continue | |
else: | |
str2 += str1[i] |
This file contains 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
def SortByFrequency(list1): | |
d1 = {} | |
list2 = [] | |
for items in list1: | |
d1[items] = list1.count(items) | |
for thekeys in d1: | |
for i in range(0,d1[thekeys]): | |
list2.append(thekeys) | |
return list2 |
This file contains 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
package lab5; | |
import java.util.ArrayList; | |
public class BinarySearchTree { | |
public class Node { | |
public int data; | |
public Node left; | |
public Node right; | |
/* | |
* Constructor if in which a value is passed, a Node |
This file contains 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
package lab5; | |
import java.util.Scanner; | |
public class DataCenterOrders { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int numOperations = in.nextInt(); | |
// create object of BinarySearchTree class | |
BinarySearchTree tree1 = new BinarySearchTree(); |
This file contains 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 QueueUsingStacks: | |
def __init__(self): | |
self.stack1 = [] | |
self.stack2 = [] | |
def enqueue(self,value): | |
self.stack1.append(value) | |
#if empty, pop from stack1 and put each value in stack2. | |
def dequeue(self): |
OlderNewer