Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
7bf62ff4
T
Third Party CJSON
项目概览
OpenHarmony
/
Third Party CJSON
大约 1 年 前同步成功
通知
6
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party CJSON
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7bf62ff4
编写于
4月 30, 2017
作者:
M
Max Bruckner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor cJSONUtils_SortList
上级
f0300581
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
50 deletion
+54
-50
cJSON_Utils.c
cJSON_Utils.c
+54
-50
未找到文件。
cJSON_Utils.c
浏览文件 @
7bf62ff4
...
...
@@ -1034,39 +1034,41 @@ static cJSON *cJSONUtils_SortList(cJSON *list)
{
cJSON
*
first
=
list
;
cJSON
*
second
=
list
;
cJSON
*
ptr
=
list
;
cJSON
*
current_item
=
list
;
cJSON
*
result
=
list
;
cJSON
*
result_tail
=
NULL
;
if
(
!
list
||
!
list
->
next
)
if
(
(
list
==
NULL
)
||
(
list
->
next
==
NULL
)
)
{
/* One entry is sorted already. */
return
lis
t
;
return
resul
t
;
}
while
(
ptr
&&
ptr
->
next
&&
(
cJSONUtils_strcasecmp
((
unsigned
char
*
)
ptr
->
string
,
(
unsigned
char
*
)
ptr
->
next
->
string
)
<
0
))
while
(
(
current_item
!=
NULL
)
&&
(
current_item
->
next
!=
NULL
)
&&
(
cJSONUtils_strcasecmp
((
unsigned
char
*
)
current_item
->
string
,
(
unsigned
char
*
)
current_item
->
next
->
string
)
<
0
))
{
/* Test for list sorted. */
ptr
=
ptr
->
next
;
current_item
=
current_item
->
next
;
}
if
(
!
ptr
||
!
ptr
->
next
)
if
(
(
current_item
==
NULL
)
||
(
current_item
->
next
==
NULL
)
)
{
/* Leave sorted lists unmodified. */
return
lis
t
;
return
resul
t
;
}
/* reset p
t
r to the beginning */
ptr
=
list
;
while
(
ptr
)
/* reset p
ointe
r to the beginning */
current_item
=
list
;
while
(
current_item
!=
NULL
)
{
/* Walk two pointers to find the middle. */
second
=
second
->
next
;
ptr
=
ptr
->
next
;
/* advances
ptr
two steps at a time */
if
(
ptr
)
current_item
=
current_item
->
next
;
/* advances
current_item
two steps at a time */
if
(
current_item
!=
NULL
)
{
ptr
=
ptr
->
next
;
current_item
=
current_item
->
next
;
}
}
if
(
second
&&
second
->
prev
)
if
(
(
second
!=
NULL
)
&&
(
second
->
prev
!=
NULL
)
)
{
/* Split the lists */
second
->
prev
->
next
=
NULL
;
...
...
@@ -1075,65 +1077,67 @@ static cJSON *cJSONUtils_SortList(cJSON *list)
/* Recursively sort the sub-lists. */
first
=
cJSONUtils_SortList
(
first
);
second
=
cJSONUtils_SortList
(
second
);
list
=
ptr
=
NULL
;
result
=
NULL
;
while
(
first
&&
second
)
/* Merge the sub-lists */
/* Merge the sub-lists */
while
((
first
!=
NULL
)
&&
(
second
!=
NULL
))
{
cJSON
*
smaller
=
NULL
;
if
(
cJSONUtils_strcasecmp
((
unsigned
char
*
)
first
->
string
,
(
unsigned
char
*
)
second
->
string
)
<
0
)
{
if
(
!
list
)
{
/* start merged list with the first element of the first list */
list
=
ptr
=
first
;
}
else
{
/* add first element of first list to merged list */
ptr
->
next
=
first
;
first
->
prev
=
ptr
;
ptr
=
first
;
}
smaller
=
first
;
}
else
{
smaller
=
second
;
}
if
(
result
==
NULL
)
{
/* start merged list with the smaller element */
result_tail
=
smaller
;
result
=
smaller
;
}
else
{
/* add smaller element to the list */
result_tail
->
next
=
smaller
;
smaller
->
prev
=
result_tail
;
result_tail
=
smaller
;
}
if
(
first
==
smaller
)
{
first
=
first
->
next
;
}
else
{
if
(
!
list
)
{
/* start merged list with the first element of the second list */
list
=
ptr
=
second
;
}
else
{
/* add first element of second list to merged list */
ptr
->
next
=
second
;
second
->
prev
=
ptr
;
ptr
=
second
;
}
second
=
second
->
next
;
}
}
if
(
first
)
if
(
first
!=
NULL
)
{
/* Append rest of first list. */
if
(
!
list
)
if
(
result
==
NULL
)
{
return
first
;
}
ptr
->
next
=
first
;
first
->
prev
=
ptr
;
result_tail
->
next
=
first
;
first
->
prev
=
result_tail
;
}
if
(
second
)
if
(
second
!=
NULL
)
{
/* Append rest of second list */
if
(
!
list
)
if
(
result
==
NULL
)
{
return
second
;
}
ptr
->
next
=
second
;
second
->
prev
=
ptr
;
result_tail
->
next
=
second
;
second
->
prev
=
result_tail
;
}
return
lis
t
;
return
resul
t
;
}
CJSON_PUBLIC
(
void
)
cJSONUtils_SortObject
(
cJSON
*
object
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录