When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
6 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
@autumn atlas
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
#include <iostream>
#include <cstdlib>
#include "adt_list.h"
using namespace std;
int main(int argc,char* argv[])
{
if (argc < 2)
{
cerr << "Usage:" << argv[0] << "K\n";
return 1;
}
int K;
K = atoi(argv[1]);
List<int> input;
int value;
while (cin >> value)
{
input.append(value);
}
List<int>::Iterator verifier = input.getHead();
while (verifier)
{
value = *verifier;
if (value % K != 0)
{
verifier.remove();
while (value % K != 0)
{
value = value + 1;
}
}
List<int>::Iterator fixer = verifier;
while (fixer && *fixer % K != 0)
{
fixer++;
}
if (fixer)
{
fixer.insert(value);
}
else
{
input.append(value);
}
verifier++;
}
for (List<int>::Iterator i = input.getHead(); i; i++)
{
cout << *i << " ";
}
cout << endl;
return 0;
}```
ill send the adt_list.h as well
template <typename T>
struct List {
T data[100];
int count = 0;
struct Iterator {
List * list;
int index;
operator bool() const {
return index >=0 && index < list->count;
}
Iterator & operator++() {
index++;
return *this;
}
Iterator operator++(int) {
Iterator t = *this;
index++;
return t;
}
Iterator & operator--() {
index--;
return *this;
}
Iterator operator--(int) {
Iterator t = *this;
index--;
return t;
}
T & operator*() {
return list->data[index];
}
T * operator->() {
return &list->data[index];
}
void insert(T value) {
for (int i=list->count-1; i>=index; i--)
list->data[i+1] = list->data[i];
list->count++;
list->data[index] = value;
}
void remove() {
for (int i=index; i<list->count-1; i++)
list->data[i] = list->data[i+1];
list->count--;
}
};
bool isEmpty() {
return count == 0;
}
Iterator getHead() {
return Iterator{this,0};
}
Iterator getTail() {
return Iterator{this,count-1};
}
void prepend(T value) {
Iterator{this,0}.insert(value);
}
void append(const T &value) {
Iterator{this,count}.insert(value);
}
};
Help with List C++(Not answered yet)