Quiz 3 Flashcards Preview

CSCI 3132 > Quiz 3 > Flashcards

Flashcards in Quiz 3 Deck (4)
Loading flashcards...
1
Q

In a linked list:

What components do you need for the print function?

A
  • Create a pointer to root
  • Check if the pointer is null
  • Check if next is NULL, print
  • loop until null and print pointer while setting pointer to next
2
Q

In a linked list:

What components do you need in a add function?

A
  • Set the an object pointer to the parameter (e.g. newnode)
  • Set newnode’s next to NULL
  • Create pointer to root
  • Check if root is null else
  • Iterate until en of list and set root to new node
3
Q

In a linked list:

What components do you need in a delete function?

A
  • Create pointer to root
  • Check if root is null
  • Check if next is null
  • Create temp node set to to the pointer
    else {
    mynode* tmp= 0;
while (ptr->GetNext() != NULL{
tmp= ptr;
ptr= ptr->GetNext();}
delete ptr;
tmp->SetNext(NULL);
return;}}
4
Q

In a linked list:

What components do you need in a length function?

A
  • Pointer to root
  • Check if null
  • Check if next is null
  • Iterate until the end
  • Increment counter