TALK IS CHEAP, SHOW ME THE CODE.

STL: Standard Template Library, the C++ standard template library, which wraps up all kinds of interfaces for us to call. vector is a class template and one kind of container. It’s a variable-length array: you can add and remove elements at the end, get the array’s size, and so on. Other containers include set, map, list, stack, queue, etc… We’re bound to use them in algorithm contests.

Read More
post @ 2018-02-19

Once you get how recursion works and understand the principle of divide and conquer, quick sort is easy to understand.

Quick sort is just what the name says: quick and efficient. No more talk, here’s the idea and the code.

Read More
post @ 2018-02-19

When we learn sorting algorithms, bubble sort is definitely one of the first. It’s the simplest and easiest to understand, so when complexity isn’t a concern it’s a pretty commonly used sorting algorithm (I use it all the time; after all, it’s just two nested for loops and a swap, really easy to remember). Next, let’s look at how the algorithm works.

Read More

Since a lot of classmates can’t get vc++6.0 to work properly, don’t know how to create projects and files, and some run into compile problems, I’m putting together a little tutorial here

Read More
post @ 2017-11-25

The Stack Abstract Data Type#

ADT Stack
Data
	 Same as a linear list. Elements have the same type, and adjacent elements have predecessor/successor relationships.
Operation
	 InitStack(*S) : Initialization; create an empty stack S.
	 DestroyStack(*S) : If the stack exists, destroy it.
	 ClearStack(*S) : Empty the stack.
	 StackEmpty(S) : Return true if the stack is empty, otherwise false.
	 GetTop(S,*e) : If the stack exists and is non-empty, return the top element of S in e.
	 Push(*S,e) : If stack S exists, insert new element e into S as its top element.
	 Pop(*S,*e) : Delete the top element of stack S and return its value in e.
	 StackLength(S) : Return the number of elements in stack S.
endADT
Read More
ADT List
Data
	The data object set of the linear list is {a1,a2,......,an}, and every element is of type DataType. Except for the first element a1, every element has exactly one direct predecessor; except for the last element an, every element has exactly one direct successor. The relationship between data elements is one-to-one.
Operation
	InitList(*L) :   Initialization; creates an empty linear list.
	ListEmpty(L) :   Returns true if the linear list is empty, otherwise false.
	ClearList(*L) :    Clears the linear list.
	GetElem(L,i,*e) :  Returns the value of the element at position i in list L via e.
	LocateElem(L,e) :  Searches list L for an element equal to the given value e; if found, returns that element's position in the list to indicate success; otherwise returns 0 to indicate failure.
	ListInsert(*L,i,e)  :    Inserts a new element e at position i in list L.
	ListDelete(*L,i,*e) :    Deletes the element at position i in list L and returns its value via e.
	ListLength(L) :          Returns the number of elements in list L.
endADT
Read More

Problem: say we have three numbers a, b, c; we want to sort them from smallest to largest. What’s the simplest way to do it?

Read More

Swapping letter case is actually really simple#

Go back to the most basic way data is stored and look at uppercase and lowercase letters as 8-bit binary: you’ll find that their low four bits are the same, while their high four bits differ slightly.

Read More
TOP