2つのリンクされたリストを比較しようとしています。リストとしてパラメータを取り、それらを比較する関数を作成したいと考えています。私は関数を投稿するつもりです。2つのリンクされたリストを関数のパラメータとして使用する
編集:この機能は動作しません。修正は歓迎されます。
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;
class queue {
private:
struct node {
int data;
node* next;
};
typedef struct node* nodeptr;
nodeptr head;
nodeptr curr;
nodeptr temp;
public: // this is where the functions go
queue();
bool empty();
void enqueue(int x);
void printL();
};
queue::queue() {
head = NULL;
curr = NULL;
temp = NULL;
}
bool queue::empty() {
bool check = false;
if (head == NULL) check = true;
return check;
}
void queue::enqueue(int x) {
nodeptr n = new node;
n->next = NULL;
n->data = x;
if (head != NULL) {
curr = head;
while (curr->next != NULL) curr = curr->next;
curr->next = n;
}
else head = n;
}
void queue::printL() {
curr = head;
while (curr->next != NULL) {
printf("%d ", curr->data);
curr = curr->next;
}
printf("\n");
}
bool check(*thetikoi, *arnitikoi) {
nodeptr a = head.thetikoi;
nodeptr b = head.arnitikoi;
while (a != NULL && b != NULL)
if (thetikoi->data != (arnitikoi->data))
return false;
a = a->next;
b = b->next;
return (a == NULL && b = NULL);
}
int main() {
queue thetikoi;
queue arnitikoi;
int r = 0;
while (r != EOF) {
scanf("%d", &r);
if (r >= 0) thetikoi.enqueue(r);
else arnitikoi.enqueue(r);
}
thetikoi.printL();
arnitikoi.printL();
return 0;
}
そして、何の問題のようですか? – NathanOliver
それは明らかに動作していない、私は間違ってリストを呼び出すと思う – Maverick98
タイプがありません... – Jarod42