Skip to content

Instantly share code, notes, and snippets.

@JeffreyZhao
Created March 27, 2012 14:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 27 You must be signed in to fork a gist
  • Save JeffreyZhao/2216546 to your computer and use it in GitHub Desktop.
Save JeffreyZhao/2216546 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();
}
@imnull
Copy link

imnull commented Mar 27, 2012

不是太会用这个,链个地址吧。
https://github.com/imnull/TMark/blob/master/TMark/MyList.cs
刚想起来,Remove还没测试,不过只是断开链和重组链,可能不会太难。太困了,天亮了再看看吧。

@onlytiancai
Copy link

https://gist.github.com/2221671 交作业了,看看

@chenshuo
Copy link

@yihuang
Copy link

yihuang commented Mar 28, 2012

我这个算作弊么。。。 https://gist.github.com/2223610

@rosiu
Copy link

rosiu commented Mar 28, 2012

为了回复才注册了一个gist用户,刚不会用这个发,直接写在回复里了,才改好,在这里,不知道我的删除实现对不对,请老赵看看https://gist.github.com/2223799

@MelvinTo
Copy link

比较粗糙的code,简单测试一下没发现问题。https://gist.github.com/2224734#

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