Question
Data structure in C++ I keep getting these warnings for my code.. dlist.cc: In member function 'void dlist::insert(dlist::node*, int)': dlist.cc:13:43: warning: missing initializer for member
Data structure in C++
I keep getting these warnings for my code..
dlist.cc: In member function 'void dlist::insert(dlist::node*, int)': dlist.cc:13:43: warning: missing initializer for member 'dlist::node::prev' [-Wmissing-field-initializers] dlist.cc: In member function 'void dlist::pop_front()': dlist.cc:33:21: error: lvalue required as left operand of assignment dlist.cc: In member function 'void dlist::pop_back()': dlist.cc:39:21: error: lvalue required as left operand of assignment dlist.cc: In member function 'bool dlist::empty()': dlist.cc:54:14: error: lvalue required as left operand of assignment dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:65:10: error: invalid initialization of reference of type 'std::ostream& {aka std::basic_ostream&}' from expression of type 'dlist::node*' dlist.cc: In function 'dlist operator+(dlist&, dlist&)': dlist.cc:94:16: error: invalid conversion from 'dlist::node*' to 'int' [-fpermissive] dlist.cc:96:8: error: 'result' was not declared in this scope dlist.cc:97:1: warning: control reaches end of non-void function [-Wreturn-type] dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:68:1: warning: control reaches end of non-void function [-Wreturn-type] dlist.cc: In member function 'bool dlist::empty()': dlist.cc:58:1: warning: control reaches end of non-void function [-Wreturn-type]
I just dont know how to fix it. I would love explanations for the correction also. Thank you!!!
#include "dlist.h"
dlist::node*dlist::at(int n){ node*current = head(); while(n != 0){ current= current->next; n--; } return current; }
void dlist::insert(node *previous, int value){ node*n = new node{value, previous -> next}; previous -> next = n; }
void dlist::del(node* which){ node*c= which -> next; which -> next = which-> next-> next; delete c; }
void dlist::push_back(int value){ insert(tail(),value); }
void dlist::push_front(int value){ insert(head(), value); }
void dlist::pop_front(){ node*n = head(); head() = head() -> next; delete n; }
void dlist::pop_back(){ node*n = tail();
tail() = tail() -> prev; }
int dlist::size(){ node*c = head(); int s = 0; while(c){ c = c -> next; s++; } return s; }
bool dlist::empty(){ if(size() = 0) return true; else return false; }
std::ostream& operator<< (std::ostream& out, dlist& l){ dlist::node*c = l.head(); while(c){ out << c; c = c-> next; return c; }
}
bool operator== (dlist& a, dlist& b){ dlist::node* ca = a.head(); dlist::node* cb = b.head(); while(ca&&cb){ if(ca-> next != cb->next) return false; else{ ca = ca->next; cb = cb->next; } }
if(ca== nullptr && cb == nullptr) return true; else return false; }
dlist operator+ (dlist& a, dlist& b){ dlist::node* ca = a.head(); dlist::node* cb = b.head(); while(ca&&cb){ int result; ca = ca -> next; cb = cb -> next; result= ca = cb; } return result; }
dlist reverse(dlist& l){ dlist l2;
dlist::node* c = l.head(); while(c){ l2.push_front(c->value); c = c-> next; } return l2; }
dlist.h
#pragma once
/* dlist.h Doubly-linked lists of ints */ #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started