Skip to content

Instantly share code, notes, and snippets.

@siqin
Forked from JeffreyZhao/gist:2216546
Created April 1, 2012 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siqin/2275807 to your computer and use it in GitHub Desktop.
Save siqin/2275807 to your computer and use it in GitHub Desktop.
// Please write an sequence list implements the interface with the required
// time complexity described in the comments. The users can add the same
// element as many times as they want, but it doesn't support the null item.
// You can use any types in .NET BCL but cannot use any 3rd party libraries.
// PS: You don't need to consider the multi-threaded environment.
interface IMyList<T> : IEnumerable<T>
{
// O(1)
// Add an item at the beginning of the list.
void AddFirst(T item);
// O(1)
// Add an item at the end of the list.
void AddLast(T itme);
// O(1)
// Remove the item from the list. If the list contains multiple
// copies/references of the item, remove one of them.
void Remove(T item);
// O(1)
// Reverse the list.
void Reverse();
}
@siqin
Copy link
Author

siqin commented Apr 1, 2012

O(1)要求了要hash,感觉起来就是很纠结的List实现,有点刻意。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment