HELP |  STORE |  SEARCH:              STUDENTS | PARENTS | EDUCATORS
CollegeBoard for Educators
 
Print Page
 > The Courses > Course Home Pages > AP Computer Science AB: Implementation Classes and Interfaces

AP Computer Science AB: Implementation Classes and Interfaces

Computer Science A
Teacher
Implementation Classes for Linked List and Tree Nodes
The implementation of list and tree structures is a part of the AB Computer Science course, but the Java standard is understandably silent about implementation details. Instructors and textbooks use a number of minor variations for implementing list and tree data structures. To facilitate a uniform style for the formulation of test questions, the AP Computer Science Exam uses the node classes that are listed in the
   Computer Science AB: Quick Reference Guide

Note to instructors: You can supply the following implementations to your students. These implementations are supplied for convenience only; students are not required to know the classes for the test.
 public class ArrayStack implements Stack 
{ 
  public ArrayStack() { array = new ArrayList(); } 
  public void push(Object x) { array.add(x); } 
  public Object pop() { return array.remove(array.size() - 1); } 
  public Object peekTop() { return array.get(array.size() - 1); } 
  public boolean isEmpty() { return array.size() == 0; } 

  private ArrayList array; 
} 

public class ListQueue implements Queue 
{ 
  public ListQueue() { list = new LinkedList(); } 

  public void enqueue(Object x) { list.addLast(x); } 
  public Object dequeue() { return list.removeFirst(); } 
  public Object peekFront() { return list.getFirst(); } 
  public boolean isEmpty() { return list.size() == 0; } 

  private LinkedList list; 
} 

public class ArrayPriorityQueue implements PriorityQueue 
{ 
  public ArrayPriorityQueue() { items = new ArrayList(); } 

  public void add(Object x) { items.add(x); } 

  public Object removeMin() 
  { Object min = peekMin(); items.remove(min); return min; } 

  public Object peekMin() 
  { 
    int minIndex = 0; 
    for (int i = 1; i < items.size(); i++) 
    { 
      if (((Comparable) items.get(i)).compareTo(items.get(minIndex)) < 0) 
      { 
         minIndex = i; 
      } 
    } 
    return items.get(minIndex); 
  } 

  public boolean isEmpty() { return items.size() == 0; } 

  private List items; 
} 
See also...
  Course Home Page Index
  Personal Profile

CONTACT |  CAREERS |  ABOUT US |  PRIVACY |  TERMS OF USE |  PRESS
Copyright © collegeboard.com, Inc.
  MY AP CENTRAL
    Personal Profile
   THE COURSES
    Course Home Pages
    Course Descriptions
    Sample Syllabi
   THE PROGRAM
    AP Toolkit: Starting an AP Program
    Achieving Equity
    AP Research and Data
    AP Scholar Awards
    AP International
   PRE-AP
    Teachers' Corner
    Workshops
    Publications
    FAQs
   HIGHER EDUCATION
    Setting Credit and Placement Policy
    Course and Exam Development
    AP Research
    Find Credit Policy Information
    Get Involved
   PROFESSIONAL DEVELOPMENT
    About Institutes and Workshops
    Online Events
    Getting Started for Teachers
    Become an AP Exam Reader
    Become a Consultant
    College Board Fellows
   THE EXAMS
    All About the Exams
    Exams Calendar
    For Coordinators
    Fees & Reductions
    Exam Questions
    Exam Tips