Redian新闻
>
讲真相:368万过路费的事是这样的吗?zzz
avatar
讲真相:368万过路费的事是这样的吗?zzz# Joke - 肚皮舞运动
h*g
1
谢了
有source最好, 不需要很advance, singly-linked list就行
avatar
p*w
2
讲真相:368万过路费的事是这样的吗?zzz
各位同志们,兄弟们,朋友们:
河南农民开大货车逃费被盘无期徒刑是这样滴
第一:这个事情是当地神威盖世的武警叔叔跟该农民签下协议,一年仅收取农民120万
元,
送农民伯伯俩WJ牌照,规定只能用于这条高速。
第二:武警叔叔专门去了高速收费站,把手续交给收费站,告诉他们,过几天就有俩大
货车
要来这里拉活,请您放行~~~
第三:出事以后,农民伯伯大哥被抓走了,农民伯伯弟弟收到信号,“不要担心,很快
就把
你哥捞出来”,弟弟还给一些人送了钱。
第四:收费站俩站长每个月收到农民伯伯的5000元的奖金/每人
第五:审这个案子的包青天乃是该法院退休院长的亲生少爷,过去是法院的法警,最近
提拔
了,但该人不具备审判长资格,哈哈哈,是无证上岗。
太复杂了
哈哈
请看新京报
avatar
g*s
3
why not do it urself. it's not a hard homework assignment.

【在 h*****g 的大作中提到】
: 谢了
: 有source最好, 不需要很advance, singly-linked list就行

avatar
t*t
4
stl有list
实现得很好
avatar
u*e
5
不如把你自己实现的发上来让别人找错
任何一本算法书上都会有链表的实现的,为什么不去看看书,自己写一个不是更好?

【在 h*****g 的大作中提到】
: 谢了
: 有source最好, 不需要很advance, singly-linked list就行

avatar
w*m
6
STL
avatar
k*r
7
我写了个实现,但远没有完整,你自己补充。如果我有时间加上心情好,我可能写个完
整的,随手写的,没太经过大脑,所以欢迎大家指正。
template
class Node
{
public:
Node(Node* next=NULL, T data=T()) : _next(next), _data(data)
{
}
Node* _next;
T _data;
};
template
class SLinkedList
{
public:
SLinkedList()
{
head = NULL;
}
void AddNode(T value)
{
Node* node = new Node;
node->_next = NULL;
node->_data = value;
if(!head)
{
head = node;
}
else
{
Node* p = head;
while(p->_next)
{
p = p->_next;
}
p->_next = node;
}
}
void PrintList()
{
if(!head)
return;
Node* p = head;
while(p)
{
cout<_data<p = p->_next;
}
}
private:
Node* head;
};
int main(int argc, char* argv[])
{
SLinkedList ll;
ll.AddNode(4);
ll.AddNode(11);
ll.AddNode(8);
ll.AddNode(16);
ll.AddNode(32);
ll.PrintList();
return 0;
}

【在 h*****g 的大作中提到】
: 谢了
: 有source最好, 不需要很advance, singly-linked list就行

avatar
w*m
8
学数据结构时候用的书实现链表的时候是用三个类
节点,迭代器,链表类
avatar
r*r
9
我当年的 homework,翻出来了。另一个 homework project, 帮我找到了第一个工作。
#ifndef LIST_H
#define LIST_H
#include
#include
#include
#include "node.h"
using namespace std;
/*=========================================================================*/
/**
* Implementation of a List ADT using a doubly-linked list.
*
* @version 1.0 2/25/05
*/
/*.........................................................................*/
/**
* Definition of exception handling class
*/
class ListEmpty : public runtime_error
{
public:
ListEmpty(const string& err) : runtime_error (err){}
};
/*.........................................................................*/
/**
* Interface defintion of class List
*/
template
class List {
public:
List();
List( const List & ) throw ( bad_alloc );
~List();
unsigned size() const;
void clear();
bool empty() const;
void push_back(const T &) throw ( bad_alloc );
void push_front(const T &) throw ( bad_alloc );
T pop_front() throw ( ListEmpty );
T pop_back() throw ( ListEmpty );
T &getFront() const throw ( ListEmpty );
T &getCurrent() const throw ( ListEmpty );
T &getBack() const throw ( ListEmpty );
void insertBeforeCurrent(const T &) throw ( ListEmpty, bad_alloc );
void insertAfterCurrent(const T &) throw ( ListEmpty, bad_alloc );
T removeCurrent() throw ( ListEmpty );
void setToFront() throw ( ListEmpty );
void setToBack() throw ( ListEmpty );
void moveForward() throw ( ListEmpty );
void moveBackward() throw ( ListEmpty );
bool find( const T & ) throw ( ListEmpty );
bool atFront() const throw ( ListEmpty );
bool atBack() const throw ( ListEmpty );
const List &operator=( const List & ) throw ( bad_alloc);
void print();
private:
Node *head, *tail;
Node *current;
unsigned sz;
}; // List class
/*------------------------------------------------------------------------*/
/**
* Default constructor.
*/
template
List::List()
{
sz = 0;
head = 0;
tail = 0;
current = 0;
} // List::List
/*------------------------------------------------------------------------*/
/**
* Copy constructor.
*
* @throws bad_alloc if memory cannot be allocated.
*/
template
List::List( const List &l ) throw ( bad_alloc )
{
if( l.sz == 0 )
{
head = tail = current = NULL;
sz = 0;
return;
}
Node *travPtr = l.head;
Node *copyToPtr = new Node(travPtr->object);
head = copyToPtr;
head->prevPtr = 0;
if( l.current == travPtr )
current = copyToPtr;

travPtr = travPtr -> nextPtr;
while (travPtr != 0)
{
copyToPtr->nextPtr = new Node(travPtr->object);
copyToPtr->nextPtr->prevPtr = copyToPtr;
copyToPtr = copyToPtr->nextPtr;
if( l.current == travPtr)
current = copyToPtr;
travPtr = travPtr->nextPtr;
}
tail = copyToPtr;
tail->nextPtr = 0;
sz = l.sz;
} // List::List
/*------------------------------------------------------------------------*/
/**
* Class destructor.
*/
template
List::~List()
{
clear();
} // List::~List
/*------------------------------------------------------------------------*/
/**
* Returns the size (i.e., number of elements) of the list.
*
* @return an unsigned integer indicating the list's size.
*/
template
unsigned List::size() const
{
return sz;
} // List::size
/*------------------------------------------------------------------------*/
/**
* Removes the elements in the list.
*/
template
void List::clear()
{
while( !empty() )
{
Node *temp = head;
head = head->nextPtr;
delete temp;
sz--;
}
head = tail = current = 0;
} // List::clear
/*------------------------------------------------------------------------*/
/**
* Returns true if the list is empty; returns false otherwise.
*
* @return true if empty; false otherwise.
*/
template
bool List::empty() const
{
return head == 0;
} // List::empty
/*------------------------------------------------------------------------*/
/**
* Adds the object to the back of the list. After adding, sets current
* to the new node.
*
* @param object the object to be added to the back of the list.
* @throws bad_alloc if memory cannot be allocated.
*/
template
void List::push_back(const T &object) throw ( bad_alloc )
{
Node *newPtr = new Node (object);

if(empty())
head = tail = current = newPtr;
else
{
tail->nextPtr = newPtr;
newPtr->prevPtr = tail;
tail = newPtr;
tail->nextPtr = 0;

current = tail;
}

sz++;
} // List::push_back
/*------------------------------------------------------------------------*/
/**
* Adds the object to the front of the list. After adding, sets current
* to the new node.
*
* @param object the object to be added to the front of the list.
* @throws bad_alloc if memory cannot be allocated.
*/
template
void List::push_front(const T &object) throw ( bad_alloc )
{
Node *newPtr = new Node (object);

if( empty() )
head = tail = current = newPtr;
else
{
newPtr->nextPtr = head;
head->prevPtr = newPtr;
head = newPtr;
head->prevPtr = 0;
current = head;
}
sz++;
} // List::push_front
/*------------------------------------------------------------------------*/
/**
* Removes and returns the object at the front of the list. If current
* points to the front of the list, then sets current to point to the
* new front of the list. Otherwise, current is left unchanged.
*
* @return the object at the front of the list.
* @throws ListEmpty if the list is empty.
*/
template
T List::pop_front() throw ( ListEmpty )
{
if( empty() )
throw ListEmpty( "Empty list found in function pop_front! " );
Node *temp = head;
if(head == tail)
head = tail = current = 0;
else
{
head = head->nextPtr;
head->prevPtr = 0;
}

if(current == temp)
current = head;
T value = temp->object;
delete temp;
sz--;

return value;
} // List::pop_front
/*------------------------------------------------------------------------*/
/**
* Removes and returns the object at the back of the list. If current
* points to the back of the list, then sets current to point to the
* new back of the list. Otherwise, current is left unchanged.
*
* @return the object at the back of the list.
* @throws ListEmpty if the list is empty.
*/
template
T List::pop_back() throw ( ListEmpty )
{
if( empty() )
throw ListEmpty( "Empty list found in function pop_back()! " );

Node *temp = tail;
if(head == tail)
head = tail = current = 0;
else
{
tail->prevPtr->nextPtr = 0;
tail = tail->prevPtr;
}
if(current == temp)
current = tail;
T value = temp->object;
delete temp;
sz--;
return value;
} // List::pop_back
/*------------------------------------------------------------------------*/
/**
* Gets, but does not remove, the object at the front of the list.
* Current is left unchanged.
*
* @return a reference to the object at the front of the list.
* @throws ListEmpty if the list is empty.
*/
template
T &List::getFront() const throw ( ListEmpty )
{
if( empty() )
throw ListEmpty( "Empty list found in function getFront()! " );
return head->object;
} // List::getFront
/*------------------------------------------------------------------------*/
/**
* Gets, but does not remove, the object pointed to by current.
*
* @return a reference to the object pointed to by current.
* @throws ListEmpty if the list is empty.
*/
template
T &List::getCurrent() const throw ( ListEmpty )
{
if( empty() )
throw ListEmpty( "Empty list found in function getCurrent()! " );
return current->object;
} // List::getCurrent
/*------------------------------------------------------------------------*/
/**
* Gets, but does not remove, the object at the back of the list.
* Current is left unchanged.
*
* @return a reference to the object at the back of the list.
* @throws ListEmpty if the list is empty.
*/
template
T &List::getBack() const throw ( ListEmpty )
{
if( empty() )
throw ListEmpty( "Empty list found in function getBack()! " );

return tail->object;
} // List::getBack
/*------------------------------------------------------------------------*/
/**
* Inserts the object before the node pointed to by current. Sets current
* to point to the new node.
*
* @param object the object to be inserted before the current node.
* @throws bad_alloc if memory cannot be allocated.
* @throws ListEmpty if the list is empty.
*/
template
void List::insertBeforeCurrent(const T &object) throw (ListEmpty, bad_
alloc)
{
if( empty() )
throw ListEmpty( "Empty list found in function insertBeforeCurrent()
! " );
Node *newNode = new Node(object);
if(head == 0)
head = tail = current = newNode;
else
{
if(current != head)
{
current->prevPtr->nextPtr = newNode;
newNode->prevPtr = current->prevPtr;
newNode->nextPtr = current;
current->prevPtr = newNode;
}
else
{
newNode->nextPtr = current;
current->prevPtr = newNode;
head = newNode;
}
}
current = newNode;
sz++;
} // List::insertBeforeCurrent
/*------------------------------------------------------------------------*/
/**
* Inserts the object after the node pointed to by current. Sets current
* to point to the new node.
*
* @param object the object to be inserted after the current node.
* @throws bad_alloc if memory cannot be allocated.
* @throws ListEmpty if the list is empty.
*/
template
void List::insertAfterCurrent(const T &object) throw (ListEmpty, bad_
alloc)
{
if( empty() )
throw ListEmpty( "Empty list found in function insertAfterCurrent()!
" );

Node *newNode = new Node(object);

if( head == 0)
head = tail = current = newNode;
else
{
if(current != tail)
{
current->nextPtr->prevPtr = newNode;
newNode->nextPtr = current->nextPtr;
current->nextPtr = newNode;
newNode->prevPtr = current;
}
else
{
current->nextPtr = newNode;
newNode->prevPtr = current;
tail = newNode;
}
}
current = newNode;
sz++;
} // List::insertAfterCurrent
/*------------------------------------------------------------------------*/
/**
* Removes and returns the object in the node pointed to by current.
* Sets current to the next node, if possible. Otherwise, it sets
* current to the previous node.
*
* @return the object in the current node.
* @throws ListEmpty if the list is empty.
*/
template
T List::removeCurrent() throw ( ListEmpty )
{
if( empty() )
throw ListEmpty( "Empty list found in function removeCurrent()! " );
Node *temp = current;
if( !empty() )
{
if( sz == 1 )
head = tail = current = 0;
else
{
if( current == head)
{
head = head->nextPtr;
head->prevPtr = 0;
current = head;
}
else
{
if( current == tail )
{
tail = tail->prevPtr;
tail->nextPtr = 0;
current = tail;
}
else
{
current->prevPtr->nextPtr = current->nextPtr;
current->nextPtr->prevPtr = current->prevPtr;
current = current->nextPtr;
}
}
}
sz--;
}
T value = temp->object;
delete temp;
return value;
} // List::removeCurrent
/*------------------------------------------------------------------------*/
/**
* Sets current to the first node in the list.
*
* @throws ListEmpty if the list is empty.
*/
template
void List::setToFront() throw ( ListEmpty )
{
if( empty() )
throw ListEmpty("Empty list found in function setToFront()! ");
current = head;
} // List::setToFront
/*------------------------------------------------------------------------*/
/**
* Sets current to the last node in the list.
* @throws ListEmpty if the list is empty.
*/
template
void List::setToBack() throw ( ListEmpty )
{
if( empty() )
throw ListEmpty("Empty list found in function setToBack()! ");
current = tail;
} // List::setToBack
/*------------------------------------------------------------------------*/
/**
* Moves current to the next node in the list. If current points to the
* end of the list, then current is left unchanged.
*
* @throws ListEmpty if the list is empty.
*/
template
void List::moveForward() throw ( ListEmpty )
{
if( empty() )
throw ListEmpty( "Empty List found in function moveForward()" );
if(current != tail)
current = current->nextPtr;
} // List::moveForward
/*------------------------------------------------------------------------*/
/**
* Move current to the previous node in the list. If current points to the
* front of the list, then current is left unchanged.
*
* @throws ListEmpty if the list is empty.
*/
template
void List::moveBackward() throw ( ListEmpty )
{
if( empty() )
throw ListEmpty( "Empty list found in function moveBackward()" );

if(current != head)
current = current->prevPtr;
} // List::moveBackward
/*------------------------------------------------------------------------*/
/**
* Returns true if the object is found in the list, and sets current to
point
* to the node containing the found item; Returns false otherwise, leaving
* current unaltered.
*
* @param object the object to be inserted after the current node.
* @return true if at the front of the list; false otherwise.
* @throws ListEmpty if the list is empty.
*/
template
bool List::find( const T &object ) throw ( ListEmpty )
{
if( empty() )
throw ListEmpty( "Empty list found in function find()! " );
Node *tempPtr = head;
while( tempPtr != 0 )
{
if(tempPtr->nextPtr != 0)
{
if(tempPtr->object == object)
{
current = tempPtr;
return true;
}
tempPtr = tempPtr->nextPtr;
}
else
{
if(tempPtr->object == object)
return true;
else
return false;
}
}

return false;
} // List::find
/*------------------------------------------------------------------------*/
/**
* Returns true if current is at the front of the list; Returns false
* otherwise.
*
* @return true if at the front of the list; false otherwise.
* @throws ListEmpty if the list is empty.
*/
template
bool List::atFront() const throw ( ListEmpty )
{
if( empty() )
throw ListEmpty("Empty list found in function atFront()!");
if( current == head )
return true;
else
return false;
} // List::atFront
/*------------------------------------------------------------------------*/
/**
* Returns true if current is at the back of the list; Returns false
* otherwise.
*
* @return true if at the back of the list; false otherwise.
* @throws ListEmpty if the list is empty.
*/
template
bool List::atBack() const throw ( ListEmpty )
{
if( empty() )
throw ListEmpty("Empty list found in function atBack()!");
if(current == tail)
return true;
else
return false;
} // List::atBack
/*------------------------------------------------------------------------*/
/**
* Returns a deep copy of the list passed in as the parameter.
*
* @param list the list to be copied.
* @return a copy of the list.
* @throws bad_alloc if memory cannot be allocated.
*/
template
const List &List::operator=( const List &list ) throw ( bad_alloc )
{
if(this != &list)
{
if( !empty() )
clear();
sz = list.sz;

if( list.sz == 0 )
{
head = tail = current = NULL;
sz = 0;
}
Node *travPtr = list.head;
Node *copyToPtr = new Node(travPtr->object);
head = copyToPtr;
head->prevPtr = 0;
if( list.current == travPtr )
current = copyToPtr;

travPtr = travPtr -> nextPtr;
while (travPtr != 0)
{
copyToPtr->nextPtr = new Node(travPtr->object);
copyToPtr->nextPtr->prevPtr = copyToPtr;
copyToPtr = copyToPtr->nextPtr;

if( list.current == travPtr)
current = copyToPtr;
travPtr = travPtr->nextPtr;
}
tail = copyToPtr;
tail->nextPtr = 0;
}
return *this;
} // List::operator=
//Print function
template
void List::print() throw ( ListEmpty )
{
if( empty() )
throw ListEmpty("Empty List found in function print()");

this->setToFront();
for(unsigned i =0; i{
cout<getCurrent()<this->moveForward();
}
}//List::print
#endif // LIST_H

【在 h*****g 的大作中提到】
: 谢了
: 有source最好, 不需要很advance, singly-linked list就行

avatar
k*r
10
迭代器是什么?

【在 w*******m 的大作中提到】
: 学数据结构时候用的书实现链表的时候是用三个类
: 节点,迭代器,链表类

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。