/*
 * Copyright ©2026 Soham Pardeshi. All rights reserved.
 * Permission is hereby granted to students registered for University of
 * Washington CSE 333 for use solely during Summer Quarter 2026 for
 * purposes of the course. No other use, copying, distribution, or
 * modification is permitted without prior written consent. Copyrights
 * for third-party components of this work must be honored. Instructors
 * interested in reusing these course materials should contact the author.
 */

#ifndef LINKEDINTLIST_H_
#define LINKEDINTLIST_H_

#include <memory>

#include "IntList.h"

namespace intlist333 {

// Implements IntList using a doubly linked list.
class LinkedIntList : public IntList {
 public:
  LinkedIntList() = default;

  LinkedIntList(const LinkedIntList& other) = delete;
  LinkedIntList& operator=(const LinkedIntList& other) = delete;

  ~LinkedIntList() override = default;

  int num_elements() const override { return num_elements_; }

  void Push(int payload) override;

  void Append(int payload) override;

  bool Pop(int* const payload_ptr) override;

  bool Slice(int* const payload_ptr) override;

 private:
  struct Node {
    int payload;
    std::shared_ptr<Node> next;
    std::weak_ptr<Node> prev;
  };

  int num_elements_ = 0;
  std::shared_ptr<Node> head_;
  std::weak_ptr<Node> tail_;
};

}  // namespace intlist333

#endif  // LINKEDINTLIST_H_