Questions

https://document.grail.moe/2bb46a83bf104075bcfd3833d2d0ccb1.pdf

No ans key tho

lets be pallas cats

Tutorial 8A

Each element/node contains data and a pointer to the next element

The last element has a null pointer signifies the end of the list

There is a head pointer, pointing to the first element of the list

If n=1, make new data item point to old first item

Make head point to new data item

else, move through list to (n-1)th data item

make pointer in new data item = pointer in (n-1)th data item

and make (n-1)th item point to new data item

Advantages of array

  • all high-level languages support arrays but not all support pointers
  • Arrays are easier to program
  • Can go directly to a data item without going through preceding items
  • Array requires less storage than linked list

Disadvantages

  • static, so must know amount of data stored early on
  • can’t grow as more data is added
  • can waste space
  • additions to or deletion from an array means the array has to be frequently reorganised, whereas, for a linked list, only a few pointers need changing