Programming - 6 - Data Structures Flashcards

1
Q

What is a Linked List?

A
  • linear collection of self-referential objects connected by reference links
  • self referential classes contain reference instance variables linking to objects, forming dynamic data structures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Linked List code example

A

public class ListNode {

private Object data; //data

private ListNode next; // self-reference

public ListNode (Object newData, ListNode newNext) {

data = newData;

next = newNext;

}

public Object getData() {…}

public ListNode getNext() {…}

public void setData(..) {…}

public void setNext(..) {…}

}

public class List {

protected ListNode firstNode;

protected ListNode lastNode;

protected String name;

public void insertAtBack (Front(Object newData) {}

public Object removefromBack/Front() {}

public ListNode getFirst() {}

public String toString() {}

public List (String listName)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a Stack?

A
  • dynamic data strcuture in which data can be inserted from the top (LIFO)
  • implemented using a linked list (through composition or inheriting)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Stack code through composition and inheriting

A

public class Stack extends List {

public Stack() { super(“Stack”);}

public void push (Object data) {…}

public Object pip() {…}

}

public class Stack{ // composition

private List stackList;

public Stack() {stackList = new List(“Stack”); }

.

.

.

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a Queue?

A
  • Data inserted at back, removed at front (FIFO)
  • used in discrete event simulations to store “events” in spooling systems
  • Implemented through composition, main methods: enqueue, dequeue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly