﻿ 數據結構 面試題 4_電腦知識網

# 數據結構 面試題 4

2022-06-13   來源: 數據結構

{
int data;
};

{
{
return false;
}
do{
p= p>next;
p = p>next>next;
} while(p &#;&#; p>next &#;&#; p!=p);
if(p == p)
return true;
else
return false;
}

int data;
};

{
return;
while(cur)
{
ne = cur>next;
cur>next = pre;
pre = cur;
cur = ne;
}
}

{
if(p == NULL || p>next == NULL)
{
return p;
}
else
{
tmp>next = p;
return p;
}
}

bool findcommon(int a[]int sizeint b[]int size)
{
int i;
for(i=;i;i++)
{
int start=end=sizemid;
while(start<=end)
{
mid=(start+end)/;
if(a[i]==b[mid])
return true;
else if (a[i] end=mid;
else
start=mid+;
}
}
return false;
}

bool findcommon(int a[] int size int b[] int size)
{
int i=j=;
while(i &#;&#; j)
{
if(a[i]==b[j])
return true;
if(a[i]>b[j])
j++;
if(a[i] i++;
}
return false;
}

int max_sub(int a[]int size)
{
int ijvmax=a[];
for(i=;i {
v=;
for(j=i;j {
v=v+a[j];//Sum(i j+) = Sum(i j) + A[j+]
if(v>max)
max=v;
}
}
return max;
}

int max_sub(int a[] int size)
{
int imax=temp_sum=;
for(i=;i {
temp_sum+=a[i];
if(temp_sum>max)
max=temp_sum;
else if(temp_sum<)
temp_sum=;
}
return max;
}

is Here

char* reverse_word(const char* str)
{
int len = strlen(str);
char* restr = new char[len+];
strcpy(restrstr);
int ij;
for(i=j=len;ij)
{
char temp=restr[i];
restr[i]=restr[j];
restr[j]=temp;
}
int k=;
while(k {
i=j=k;
while(restr[j]!= &#;&#; restr[j]!= )
j++;
k=j+;
j;
for(;ij)
{
char temp=restr[i];
restr[i]=restr[j];
restr[j]=temp;
}
}
return restr;
}

char temp=restr[i];
restr[i]=restr[j];
restr[j]=temp;

restr[i]^=restr[j];
restr[j]^=restr[i];
restr[i]^=restr[j];

#include
#include
using namespace std;
//remove the duplicated numbers in an intger array the array was end with ;
//eg &#;>
void static remove_duplicated(int a[] vector&#; _st)
{
_stpush_back(a[]);
for(int i=;_st[_stsize()]!=;i++)
{
if(a[i]!=a[i])
_stpush_back(a[i]);
}
}

void static remove_duplicated(int a[])
{
if(a[]== || a==NULL)
return;
int insert=current=;
while(a[current]!=)
{
if(a[current]!=a[current])
{
a[insert]=a[current];
insert++;
current++;
}
else
current++;
}
a[insert]=;
}

template
static int Depth(BSTreeNode* pbs)
{
if (pbs==NULL)
return ;
else
{
int ld = Depth(pbs>left);
int rd = Depth(pbs>right);
return + (ld >rd ? ld : rd);
}
}

template
static bool isBalance(BSTreeNode* pbs)
{
if (pbs==NULL)
return true;
int dis = Depth(pbs>left) &#; Depth(pbs>right);
if (dis> || dis< )
return false;
else
return isBalance(pbs>left) &#;&#; isBalance(pbs>right);
}

From:http://tw.wingwit.com/Article/program/sjjg/201405/30935.html
• 上一篇文章：

• 下一篇文章：