开发者

creating multiple link lists

I am supposed to save content of book in linked list i.e

Each book will have many chapters.so one type of linkedlist will be of chapters .Each chapter will be having many sections.Hence each of the chapter node should point to a list of sections.Each section contains multiple paragraphs.so each of the subtopic node should point to a list of paragraphs..how can i 开发者_如何学JAVAimplement this

thanks in advance


That sounds like you'd have something like:

class Book
{
    private final LinkedList<Chapter> chapters;
    // Other stuff
}

class Chapter
{
    private final Linkedist<Section> sections;
    // Other stuff
}

class Section
{
    private final Linkedist<Paragraph> paragraphs;
    // Other stuff
}

(You may very well choose to declare the variables themselves to be of type List<E> or perhaps Deque<E>, using LinkedList<E> only when creating the actual objects that the variables refer to. I've only used the concrete type here for brevity.)


You have to make 4 classes :

  1. Book
  2. Chapter
  3. Section
  4. Paragraph

The Book class will hold field of type List<Chapter>. The Chapter class will hold a field of type List<Section>. The Section class will hold a field of type List<Paragraph>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜