2012/06/11 Algorithm 4th Edition 互动贴 (1.3 Bags, Queues, and Stacks)

54 views
Skip to first unread message

Zhihao

unread,
Jun 12, 2012, 9:42:19 PM6/12/12
to algorit...@googlegroups.com
教材PDF: Click Me

课件: Click Me

习题从教材第 161 页开始

Deadline: 6/12 完成


问题及答案请回复本主题

weibing

unread,
Jun 14, 2012, 12:07:00 AM6/14/12
to algorit...@googlegroups.com

Interface of Bags, Queues, Stack.

Bag

public class Bag <Item> implements Iterable<Item>
{
Bag()                       //create an emtpy bag
void add(Item item)   //add an item
boolean isEmpty()    //is the bag empty? 
int  size()                 //number of items in the bag
}

FIFO queue
public class Queue<Item> implements Iterable<Item>
{
Queue();
void enqueue(Item item);
Item dequeue();
boolean isEmpty();
int size();
}

Pushdown(LIFO) stack
public class Stack<Item> implements Iterable<Item>
{
Stack()
void Push(Item item);
Item pop();
boolean isEmpty();
int size();
}
-------------------------------------------------------------------------------
        APIs for fundamental generic iterable collections
Reply all
Reply to author
Forward
0 new messages