由买买提看人间百态

topics

全部话题 - 话题: intlist
(共0页)
Q**g
发帖数: 183
1
来自主题: Programming版 - A weird segmentation fault!
change:
IntList.h
void operator=(IntList newList);
==>
void operator=(IntList& newList);
and
IntList.cpp
void IntList::operator=(IntList newList)
==>
void IntList::operator=(IntList& newList)
if you have "void operator=(IntList newList)", there is a copy construction
involved and a temp object is created in a bitwise copying fashion. When the
temp goes out of the scope, its destructor destroys the list which is
shared with your actual parameter.
a******h
发帖数: 19
2
来自主题: JobHunting版 - 问2道面试题
I use dynamic programming to solve Q2. My solution required a sorted
integer array as input. The boolean array is the solution.
public static void main (String [] args) {
int [] intList = {1, 3, 5, 6, 8, 9, 11, 12};
boolean [] boolList = subsetSum(intList, 10);
System.out.println(Arrays.toString(intList));
System.out.println(Arrays.toString(boolList));

}
public static boolean [] subsetSum(int [] intList, int sum) {
if (su
m*********e
发帖数: 37
3
来自主题: Programming版 - A weird segmentation fault!
Attached is the implementation of the List class:
IntList.h
*****************************************************
#ifndef _INTLIST_H_
#define _INTLIST_H_
#define NULL 0
class IntItem
{
public:
IntItem()
{
//itm = -1;
nxt = NULL;
}
IntItem(int value, IntItem * n = NULL):itm(value), nxt(n){}
int itm;
IntItem *nxt;
};
class IntList
{
public:
IntItem *list;
mutable IntItem *curr;
IntList();
~IntList();
void add
c******r
发帖数: 300
4
来自主题: Java版 - 问个初级的generic的问题
我想完成以下的功能
List intList = new ArrayList();
List strList = new ArrayList();
List cmpList;
cmpList = intList;
// do something like
Collections.sort(cmpList);
System.out.println(cmpList);
cmpList = strList;
// do similar thing
可是上面的代码会有warning 有什么办法可以解决这个warning?
我知道可以写个函数
void > doSth(List cmpList)
{
Collections.sort(cmpList);
System.out.println(cmpList);
}
不过请问一般情况下这个该怎么办呢? 多谢。
m*********e
发帖数: 37
5
来自主题: Programming版 - A weird segmentation fault!
I implemented a simple list class. There is a member function "=", which
define the assignment two list.
When I am testing the list class with following code, I got very weird
segmentation fault.
******************************************************
int main()
{
IntList a;
int i;
for(i=0; i<3; i++)
{
a.add_entry(1);
}
IntList b;
for(i=0; i<1; i++)
{
b.add_entry(100);
}
char s;
m*********e
发帖数: 37
6
来自主题: Programming版 - A weird segmentation fault!
Thanks! I did bt under g++3.2, it said something wrong with concat_list();
I am testing under g++ 4.0.2. The cause it tells now is because in "="
function, I delete the ptr twice.(I don't understand why it happened!)
********************************
void IntList::operator=(IntList newList)
{
IntItem *nptr;
IntItem *ptr = list;
while (ptr)
{
nptr = ptr->nxt;
delete(ptr); //glibc detected here...
ptr = nptr;
}
b***y
发帖数: 2799
7
来自主题: Programming版 - [合集] how to copy a list?
☆─────────────────────────────────────☆
kindom (天道酬勤) 于 (Fri Sep 23 15:20:58 2005) 提到:
Sorry I could not input Chinese here.
For example, I have a list defined as:
////////////////////////////////////////
typedef std::list IntList;
struct SOMESTRUCT {
IntList * ants;
int num;
};
typedef std::list SomeList;
////////////////////////////////////////
I defined a list of type SomeList in the code:
SomeList * platoon = new SomeList();
Then I put some elements of type SOMESTRU
(共0页)