Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. // Sequence: provides an Integer Sequence ADT
  2. // NOTE: ALL sequence parameters must be valid
  3.  
  4. struct sequence;
  5.  
  6. // sequence_create() returns a pointer to a new (empty) sequence
  7. // effects: allocates memory (caller must call sequence_destroy)
  8. // time: O(1)
  9. struct sequence *sequence_create(void);
  10.  
  11. // sequence_destroy(seq) frees all dynamically allocated memory
  12. // effects: the memory at seq is invalid (freed)
  13. // time: O(n)
  14. void sequence_destroy(struct sequence *seq);
  15.  
  16. // sequence_length(seq) returns the number of items in seq
  17. // time: O(1)
  18. int sequence_length(const struct sequence *seq);
  19.  
  20. // sequence_item_at(seq, pos) returns the item in seq at position pos
  21. // requires: 0 <= pos < sequence_length(seq)
  22. // time: O(i) where i is pos described above
  23. int sequence_item_at(const struct sequence *seq, int pos);
  24.  
  25. // sequence_insert_at(seq, pos, val) inserts a new item with value val
  26. // at position pos in seq
  27. // (changing the position of items at position >= pos)
  28. // requires: 0 <= pos <= sequence_length(seq)
  29. // effects: seq is modified
  30. // time: O(i) where i is pos described above
  31. void sequence_insert_at(struct sequence *seq, int pos, int val);
  32.  
  33. // sequence_remove_at(seq, pos) removes the item at position pos in seq
  34. // and returns the removed value
  35. // (changing the position of items > pos)
  36. // requires: 0 <= pos < sequence_length(seq)
  37. // effects: seq is modified
  38. // time: O(i) where i is pos described above
  39. int sequence_remove_at(struct sequence *seq, int pos);
  40.  
  41. // sequence_print(seq) prints out the items in seq
  42. // using the format: "[item_0,item_1,...,item_last]\n"
  43. // or "[empty]\n"
  44. // effects: prints out a message
  45. // time : O(n)
  46. void sequence_print(const struct sequence *seq);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement