x*a
2 楼
//main()
#include
#include
#include "linkedlist.h"
int main()
{
LinkedList myList(5, "luke");
Iterator myIterator=myList.begin();
myList.insert(myIterator, "leia");
myIterator.forward();
myList.erase(myIterator);
myList.insert(myIterator, "chewbca"); 《======出问题。
myList[2]="han";
for (int i=0; i std::cout<}
myList.insert(myIterator, "chewbca"); 《======出问题。
这一句运行起来take forever:test了一下,好像前面erase一个元素对insert有影响?
//linkedlist.h
#ifndef __linkedlist__linkedlist__
#define __linkedlist__linkedlist__
#include
template class LinkedList;
template class Iterator;
template class Node;
template
class Node{
public:
Node(T newData);
friend class LinkedList;
friend class Iterator;
private:
T data;
Node* next;
Node* prev;
};
template
Node::Node(T newData){
data= newData;
next= NULL;
prev= NULL;
}
template
class Iterator{
public:
Iterator();
T get() const;//return data value we point to
void forward();
void backward();
bool isNull();
friend class LinkedList;
private:
Node* position;
};
template
Iterator::Iterator(){
position=NULL;
}
template
T Iterator::get() const{
return position->data;
}
template
void Iterator::forward(){
position=position->next;
}
template
void Iterator::backward(){
position=position->prev;
}
template
bool Iterator::isNull(){
return(position==NULL);
}
template
class LinkedList{
public:
LinkedList();
LinkedList(int numNodes, T defaultValue);
LinkedList(const LinkedList& right);
LinkedList& operator=(const LinkedList& right);
~LinkedList();
void erase(Iterator iter);
void insert(Iterator iter, T value);
Iterator begin() const;
Iterator end() const;
unsigned int size() const;
T& operator[](int index);
private:
Node* first;
Node* last;
};
template< typename T>
LinkedList::LinkedList(){
first=NULL;
}
template
Iterator LinkedList::begin() const{
Iterator iter;
iter.position=first;
return iter;
}
template
void LinkedList::erase(Iterator iter){
Node* pos=iter.position;
iter.forward();
if (pos==first)
first=pos->next;
else
(pos->prev)->next= pos->next;
if (pos==last)
last=pos->prev;
else
(pos->next)->prev=pos->prev;
delete pos;
return;
}
template
LinkedList::~LinkedList(){
while(first!=NULL)
erase(begin());
}
template
void LinkedList::insert(Iterator iter, T value){
Node* pos=iter.position;
Node* newNode=new Node(value);
if(first==NULL){
first=newNode;
last=newNode;
return;
}
newNode->prev=pos->prev;
newNode->next=pos;
if (newNode->prev==NULL){
first=newNode;
}else{
(newNode->prev)->next=newNode;
}
pos->prev=newNode;
return;
}
template
LinkedList::LinkedList(int numNodes, T defaultValue){
first=NULL;
last =NULL;
for(int i=0;i insert(begin(), defaultValue);
}
template
LinkedList::LinkedList(const LinkedList& right){
first=NULL;
last=NULL;
Iterator iter_right=right.end();
while (!iter_right.isNull) {
insert(begin(), iter_right.get());
iter_right.backward();
}
}
//LinkedList operator=(const LinkedList& right);
template
LinkedList& LinkedList::operator=(const LinkedList& right){
if(this!=&right){
Iterator iter_left=begin();
while (iter_left.position!=NULL) {
erase(iter_left);
iter_left=begin();
}
Iterator iter_right= right.end();
while (!iter_right.isNull) {
insert(begin(), iter_right.get());
iter_right.backward();
}
}
return *this;
}
template
unsigned int LinkedList::size() const{
Iterator iter=begin();
int length=0;
while (!iter.isNull()) {
iter.forward();
length++;
}
return length;
}
template
T& LinkedList::operator[](int index){
Node* pos=first;
for(int i=0; i pos=pos->next;
}
return pos->data;
}
#endif /* defined(__linkedlist__linkedlist__) */
#include
#include
#include "linkedlist.h"
int main()
{
LinkedList
Iterator
myList.insert(myIterator, "leia");
myIterator.forward();
myList.erase(myIterator);
myList.insert(myIterator, "chewbca"); 《======出问题。
myList[2]="han";
for (int i=0; i
myList.insert(myIterator, "chewbca"); 《======出问题。
这一句运行起来take forever:test了一下,好像前面erase一个元素对insert有影响?
//linkedlist.h
#ifndef __linkedlist__linkedlist__
#define __linkedlist__linkedlist__
#include
template
template
template
template
class Node{
public:
Node(T newData);
friend class LinkedList
friend class Iterator
private:
T data;
Node* next;
Node* prev;
};
template
Node
data= newData;
next= NULL;
prev= NULL;
}
template
class Iterator{
public:
Iterator();
T get() const;//return data value we point to
void forward();
void backward();
bool isNull();
friend class LinkedList
private:
Node
};
template
Iterator
position=NULL;
}
template
T Iterator
return position->data;
}
template
void Iterator
position=position->next;
}
template
void Iterator
position=position->prev;
}
template
bool Iterator
return(position==NULL);
}
template
class LinkedList{
public:
LinkedList();
LinkedList(int numNodes, T defaultValue);
LinkedList(const LinkedList
LinkedList
~LinkedList();
void erase(Iterator
void insert(Iterator
Iterator
Iterator
unsigned int size() const;
T& operator[](int index);
private:
Node
Node
};
template< typename T>
LinkedList
first=NULL;
}
template
Iterator
Iterator
iter.position=first;
return iter;
}
template
void LinkedList
Node
iter.forward();
if (pos==first)
first=pos->next;
else
(pos->prev)->next= pos->next;
if (pos==last)
last=pos->prev;
else
(pos->next)->prev=pos->prev;
delete pos;
return;
}
template
LinkedList
while(first!=NULL)
erase(begin());
}
template
void LinkedList
Node
Node
if(first==NULL){
first=newNode;
last=newNode;
return;
}
newNode->prev=pos->prev;
newNode->next=pos;
if (newNode->prev==NULL){
first=newNode;
}else{
(newNode->prev)->next=newNode;
}
pos->prev=newNode;
return;
}
template
LinkedList
first=NULL;
last =NULL;
for(int i=0;i
}
template
LinkedList
first=NULL;
last=NULL;
Iterator
while (!iter_right.isNull) {
insert(begin(), iter_right.get());
iter_right.backward();
}
}
//LinkedList
template
LinkedList
if(this!=&right){
Iterator
while (iter_left.position!=NULL) {
erase(iter_left);
iter_left=begin();
}
Iterator
while (!iter_right.isNull) {
insert(begin(), iter_right.get());
iter_right.backward();
}
}
return *this;
}
template
unsigned int LinkedList
Iterator
int length=0;
while (!iter.isNull()) {
iter.forward();
length++;
}
return length;
}
template
T& LinkedList
Node
for(int i=0; i
}
return pos->data;
}
#endif /* defined(__linkedlist__linkedlist__) */
b*7
3 楼
各位宝妈宝爸们,
有没有什么安全有效的方法可以让1岁半的宝宝戒掉吃拇指的习惯?
我女儿现在的大拇指都吃出老茧来了,而且小门牙好像也可以有一点点受影响了,所以
已经到了非戒不可的时候了。小家伙,平时玩的时候也不吃手,快睡的时候就一直
要吃手,把她的手一拉出嘴巴来,就大哭大闹。唉,真是头大。。。
有没有什么安全有效的方法可以让1岁半的宝宝戒掉吃拇指的习惯?
我女儿现在的大拇指都吃出老茧来了,而且小门牙好像也可以有一点点受影响了,所以
已经到了非戒不可的时候了。小家伙,平时玩的时候也不吃手,快睡的时候就一直
要吃手,把她的手一拉出嘴巴来,就大哭大闹。唉,真是头大。。。
I*9
4 楼
你不理it就会一直research下去。。。
l*8
5 楼
这么长。。。
k*b
6 楼
实在不行就上奶嘴?
到2岁多再戒掉。
这个年龄段的小孩,靠吸手指或奶嘴来得到安慰可能还是一种合理需求。
到2岁多再戒掉。
这个年龄段的小孩,靠吸手指或奶嘴来得到安慰可能还是一种合理需求。
P*r
13 楼
我的信用卡被Staples的单子触发fraud protection了。。非常之郁闷。。
只能换成debit card。。不过换了就寄出来了
只能换成debit card。。不过换了就寄出来了
x*a
16 楼
Thanks a lot! it worked.
再请教一个问题:我想历遍一个通过frontinsert生成的linkedlist,为什么看不到第
一个insert的元素?谢谢
#include
#include "singlylinkedlist.h"
int main(int argc, const char * argv[])
{
SingleLinkedList aList;
int i=0;
while(i<10){
aList.firstInsert(i);
++i;
}
aList.traverse();
}
输出是
9 8 7 6 5 4 3 2 1
没有0
template< typename T> class ListElement;
template< typename T> class SingleLinkedList;
template
class ListElement{
public:
ListElement(const T& value): data(value), next(NULL) {}
~ListElement();
friend class SingleLinkedList;
friend class myIterator;
private:
T data;
ListElement* next;
};
template
class SingleLinkedList{
public:
SingleLinkedList(): head(NULL) {}
~SingleLinkedList(){}
bool isEmpty(){ return (head==NULL);}
void firstInsert(const T& val);
void traverse() const;
private:
ListElement* head;
};
template
void SingleLinkedList::firstInsert(const T& val) {
ListElement* newData= new ListElement(val);
newData->next= head;
head=newData;
}
template
void SingleLinkedList::traverse() const{
ListElement* pt=head;
while (pt->next!=NULL) {
std::cout<data<pt=pt->next;
}
std::cout<< std::endl;
}
【在 l*********8 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: myIterator = myList.erase(myIterator);
:
: work
再请教一个问题:我想历遍一个通过frontinsert生成的linkedlist,为什么看不到第
一个insert的元素?谢谢
#include
#include "singlylinkedlist.h"
int main(int argc, const char * argv[])
{
SingleLinkedList
int i=0;
while(i<10){
aList.firstInsert(i);
++i;
}
aList.traverse();
}
输出是
9 8 7 6 5 4 3 2 1
没有0
template< typename T> class ListElement;
template< typename T> class SingleLinkedList;
template
class ListElement{
public:
ListElement(const T& value): data(value), next(NULL) {}
~ListElement();
friend class SingleLinkedList
friend class myIterator
private:
T data;
ListElement* next;
};
template
class SingleLinkedList{
public:
SingleLinkedList(): head(NULL) {}
~SingleLinkedList(){}
bool isEmpty(){ return (head==NULL);}
void firstInsert(const T& val);
void traverse() const;
private:
ListElement
};
template
void SingleLinkedList
ListElement
newData->next= head;
head=newData;
}
template
void SingleLinkedList
ListElement
while (pt->next!=NULL) {
std::cout<
}
std::cout<< std::endl;
}
【在 l*********8 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: myIterator = myList.erase(myIterator);
:
: work
B*f
20 楼
基本无解,至少在我儿子身上没用。试过的办法:涂黄连水,擦生姜片,涂风油精,等
等等,没试辣椒,怕弄到眼睛里。我儿子不光睡前吃,什么时候闲着了,手指头肯定在
嘴里。到3岁半左右,自己就不吃了。
等等,没试辣椒,怕弄到眼睛里。我儿子不光睡前吃,什么时候闲着了,手指头肯定在
嘴里。到3岁半左右,自己就不吃了。
f*e
21 楼
我们这个吃到四岁多了, 还在吃. 无解.
S*s
22 楼
看到这个标题的时候我意识到我正在咬拇指。
这个没关系吧。
这个没关系吧。
c*m
25 楼
总结:
如何让1岁半的宝宝戒掉吃拇指的习惯?
让时间来解决。
过了一段时间,1岁半的宝宝就不存在了,成了2岁的宝宝了。
所以问题就解决了。
如何让1岁半的宝宝戒掉吃拇指的习惯?
让时间来解决。
过了一段时间,1岁半的宝宝就不存在了,成了2岁的宝宝了。
所以问题就解决了。
相关阅读
说几个鸡肋专业,家长们注意了说说你们小时候因为父母的疏忽在身体上留下了哪些缺陷?还好我爸小学没毕业,别人家的孩子就是这么严格父母找人谈房屋拆迁,7岁男孩被遗忘车内窒息而亡!早婚早育,避免中年焦虑一个好的名字会让人印象深刻感觉好对不起老大啊给在金融公司实习的孩子的建议17岁网红男孩"杀鱼弟"喝下剧毒农药自杀,背后故事令人心酸..不要让孩子难堪请问小孩小学该跳级吗?没有血缘关系的亲情40减为什么让孩子学编程?关于这个二胎的问题只剩三个位子,beestar 9-12年级团你就是来美国谋生的,你和劳模有啥区别? (转载)14岁儿子有网瘾沉迷写小说,作为单亲妈妈我该怎么办父亲的脆弱瞬间为什么不让孩子去一线城市读书?父母的错!