数据为:id pid 183 0
184 183185 184186 185187 186188 186189 183这样的数据结构
函数parentid(int id)能得到pid
现在已知一个id号id=188,我要得到pid为0的记录
请问这段代码我该怎样写?
184 183185 184186 185187 186188 186189 183这样的数据结构
函数parentid(int id)能得到pid
现在已知一个id号id=188,我要得到pid为0的记录
请问这段代码我该怎样写?
貌似只能用parentid(int id)来判断所有的id
看看pid是不是为0了
while( parendid(id)!=0) id=parendid(id)循环结束后,id的值即所求。
parentid(int id){
pid = getPid(id);
if(pid == 0){
得到记录id,pid;
}else {
parentid(pid);
}
}
id=188;
while( parendid(id)!=0) id=parentid(id) ;
{
int pid=-1;
/*
这里你的代码根据 ID得到PID
下面假设pid已经有值了
*/
if (pid==-1)
{
//这里应该数据库异常了
}
else if (pid==0)
{
return pid;
}
else
{
getRootNode(pid)
}}
int id = 188;
int pid;
while((pid=parentid(id)) != 0)
id = pid;
public int isparentid(int id) throws Exception {
int pids;
childclass chclass=new childclass();
baseclass bclass=new baseclass();
bclass=chclass.idclass(id);
String pid=bclass.getParentID();
pids=Integer.parseInt(pid);
while(pids!=0)
{
id=pids;
}
return pids;
} public static void main(String[] args) {
childclass dd=new childclass();
try {
int d=dd.isparentid(188);
System.out.print(d);
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
死了,什么也没有出来呢