Skip to content

Instantly share code, notes, and snippets.

@eazybit
eazybit / SetOfStacks.cpp
Last active August 29, 2015 14:03
[C++] - Set of Stacks
///////////////////////////////////////////////////////////////////////////
// SetOfStacks.cpp //
// ver 1.0 //
// Type: source file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// zyu.1106@gmail.com //
// yzhan39@syr.edu //
// Description: http://www.yu-zhang.net/blog/2014/07/13/cci150-c-3-3-set-of-stacks///
@eazybit
eazybit / MinStack.cpp
Last active August 29, 2015 14:03
[C++] - Implement a stack that supports push(), pop(), top(), min() with O(1) complexity
///////////////////////////////////////////////////////////////////////////
// MinStack.cpp //
// ver 1.0 //
// Type: source file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// zyu.1106@gmail.com //
// yzhan39@syr.edu //
// Description: http://www.yu-zhang.net/blog/2014/07/12/interview-question-describe-design-a-stack-that-supports-push-pop-and-min-with-o1-complexity///
@eazybit
eazybit / Palindrome.cpp
Created July 11, 2014 01:55
[C++] - Check if a linked list is a palindrome
///////////////////////////////////////////////////////////////////////////
// Palindrome.cpp //
// ver 1.0 //
// Type: source file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// yzhan39@syr.edu //
// Description: //
///////////////////////////////////////////////////////////////////////////
@eazybit
eazybit / SingList.h
Last active August 29, 2015 14:03
[C++] - Sum two linked lists and use a linked list to represent the result (Backward: 1->2->3 + 2->9 = 3->1->4 Forward: 3->2->1 + 9->2 = 4->1->3)
///////////////////////////////////////////////////////////////////////////
// SingleList.h //
// ver 1.0 //
// Type: header file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// yzhan39@syr.edu //
// Description: http://www.yu-zhang.net/blog/2014/07/10/cci150-c-sum-two-linked-lists-and-use-a-linked-list-to-represent-backward-1-2-3-2-9-3-1-4-forward-3-2-1-9-2-4-1-3/////
///////////////////////////////////////////////////////////////////////////
@eazybit
eazybit / Partition.cpp
Last active August 29, 2015 14:03
[C++] - Partition a singly linked list around value x
///////////////////////////////////////////////////////////////////////////
// Partition.cpp //
// ver 1.0 //
// Type: source file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// yzhan39@syr.edu //
// Description: http://www.yu-zhang.net/blog/2014/07/10/cci150-c-partition-a-linked-list-around-value-x///
///////////////////////////////////////////////////////////////////////////
@eazybit
eazybit / KthToTheLast.cpp
Last active August 29, 2015 14:03
[C++] - Find the kth to the last element in a singly linked list
///////////////////////////////////////////////////////////////////////////
// KthToTheLast.cpp //
// ver 1.0 //
// Type: source file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// yzhan39@syr.edu //
// Description: //
///////////////////////////////////////////////////////////////////////////
@eazybit
eazybit / RemoveDuplicates.cpp
Last active August 29, 2015 14:03
[C++] - Remove Duplicates From a Singly Linked List (also included implementation of a template singly linked list)
///////////////////////////////////////////////////////////////////////////
// RemoveDuplicates.cpp //
// ver 1.0 //
// Type: source file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// yzhan39@syr.edu //
// Description: http://www.yu-zhang.net/blog/2014/07/10/cci150-c-remove-duplicates-from-an-unsroted-linked-list///
///////////////////////////////////////////////////////////////////////////
@eazybit
eazybit / SingleList.cpp
Last active August 29, 2015 14:03
[C++] - Singly Linked List
///////////////////////////////////////////////////////////////////////////
// SingleList.cpp //
// ver 1.0 //
// Type: source file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// yzhan39@syr.edu //
// Description: //
///////////////////////////////////////////////////////////////////////////
@eazybit
eazybit / RotateMatrix.cpp
Last active August 29, 2015 14:03
[C++] - Rotate a Matrix
///////////////////////////////////////////////////////////////////////////
// RotateMatrix.cpp //
// ver 1.0 //
// Type: source file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// yzhan39@syr.edu //
// Description: http://www.yu-zhang.net/blog/2014/07/08/cci150-c-rotate-a-nn-matrix-by-90-degrees///
///////////////////////////////////////////////////////////////////////////
@eazybit
eazybit / SetZero.cpp
Last active August 29, 2015 14:03
[C++] - If an element in an M*N matrix is 0, set its entire row and column to 0.
///////////////////////////////////////////////////////////////////////////
// SetZero.cpp //
// ver 1.0 //
// Type: source file //
// Language: C++ //
// Platform: Dell Alienware M14x, Win8 //
// Author: Yu Zhang, Syracuse University //
// yzhan39@syr.edu //
// Description: http://www.yu-zhang.net/blog/2014/07/08/cci150-c-if-an-element-in-an-mn-matrix-is-0-set-its-entire-row-and-column-to-0///
///////////////////////////////////////////////////////////////////////////