Skip to content

Instantly share code, notes, and snippets.

View ivycheung1208's full-sized avatar

Jingyi Zhang ivycheung1208

View GitHub Profile
@ivycheung1208
ivycheung1208 / 2_3.cpp
Created June 28, 2014 01:51
CC150 2.3
/* CC150 2.3
* Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
* EXAMPLE
* Input: the node c from the linked list a->b->c->d->e
* Result: nothing isreturned, but the new linked list looks like a->b->d->e
*/
#include <iostream>
using namespace std;
@ivycheung1208
ivycheung1208 / 2_4.cpp
Last active August 29, 2015 14:03
CC150 2.4
/* CC150 2.4
* Write code to partition a linked list around a value x,
* such that all nodes less than x come before all nodes greater than or equal to x.
*/
#include <iostream>
#include <list>
using namespace std;
@ivycheung1208
ivycheung1208 / 2_5.cpp
Last active August 29, 2015 14:03
CC150 2.5
/* CC150 2.5
* You have two numbers represented by a linked list, where each node contains a single digit.
* The digits are stored in reverse order, such that the Ts digit is at the head of the list.
* Write a function that adds the two numbers and returns the sum as a linked list.
* EXAMPLE
* Input:(7-> 1 -> 6) + (5 -> 9 -> 2).That is,617 + 295.
* Output: 2 -> 1 -> 9.That is, 912.
* FOLLOW UP
* Suppose the digits are stored in forward order. Repeat the above problem. EXAMPLE
* Input:(6 -> 1 -> 7) + (2 -> 9 -> 5).That is,617 + 295.
@ivycheung1208
ivycheung1208 / 2_6.cpp
Last active August 29, 2015 14:03
CC150 2.6
/* CC150 2.6
* Given a circular linked list, implement an algorithm which returns the node at the beginning of the loop.
* DEFINITION
* Circular linked list: A (corrupt) linked list in which a node's next pointer points to an earlier node,
* so as to make a loop in the linked list.
* EXAMPLE
* Input:A ->B->C->D->E->C [the same C as earlier]
* Output:C
*/
@ivycheung1208
ivycheung1208 / 2_7.cpp
Last active August 29, 2015 14:03
CC150 2.7
/* CC150 2.7
* Implement a function to check if a linked list is a palindrome.
*/
#include <iostream>
#include <list>
#include <stack>
using namespace std;
@ivycheung1208
ivycheung1208 / MyQueue.h.cpp
Last active August 29, 2015 14:03
CC150 3.5 Class Beta
/* CC150 3.5
* Implement a MyQueue class which implements a queue using two stacks.
*/
#ifndef MYQUEUEBETA_H
#define MYQUEUEBETA_H
#include <iostream>
#include <stack>
@ivycheung1208
ivycheung1208 / 3_6.cpp
Last active August 29, 2015 14:03
CC150 3.6
/* CC150 3.6
* Write a program to sort a stack in ascending order (with biggest items on top).
* You may use at most one additional stack to hold items, but you may not copy the elements into any other
* data structure (such as an array).The stack supports the following operations: push, pop, peek, and isEmpty.
*/
#include <iostream>
#include <stack>
using namespace std;
@ivycheung1208
ivycheung1208 / AnimalQueue.h.cpp
Created July 3, 2014 03:23
CC150 3.7 My Class
/* CC150 3.7
* Create the data structure to mantain a animal shelter system
* and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat
*/
#ifndef ANIMALQUEUE_H
#define ANIMALQUEUE_H
#include <iostream>
#include <string>
@ivycheung1208
ivycheung1208 / AnimalQueueSln.h.cpp
Created July 3, 2014 03:25
CC150 3.7 Solution Class
/* CC150 3.7
* Create the data structure to mantain a animal shelter system
* and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat
*/
#ifndef ANIMALQUEUESLN_H
#define ANIMALQUEUESLN_H
#include <iostream>
#include <string>
@ivycheung1208
ivycheung1208 / 3_4.cpp
Last active August 29, 2015 14:03
CC150 3.4
/* CC150 3.4
* Classic problem of the Towers of Hanoi
* http://en.wikipedia.org/wiki/Tower_of_Hanoi
*/
#include <iostream>
#include <stack>
using namespace std;