Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ZhengYi
C-PL-Solution
Commits
1c972109
Commit
1c972109
authored
Dec 14, 2021
by
Martin77
Browse files
remain free memory
parent
3f6120c1
Changes
8
Hide whitespace changes
Inline
Side-by-side
10-struct/cmake-build-debug/CMakeFiles/stackPour.dir/C.includecache
0 → 100644
View file @
1c972109
#IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">])
#IncludeRegexScan: ^.*$
#IncludeRegexComplain: ^$
#IncludeRegexTransform:
D:/C-PL/2021-C-PL-Solution/10-struct/stackPour.c
stdio.h
-
malloc.h
-
10-struct/cmake-build-debug/CMakeFiles/stackPour.dir/depend.internal
0 → 100644
View file @
1c972109
# CMAKE generated file: DO NOT EDIT!
# Generated by "MinGW Makefiles" Generator, CMake Version 3.20
CMakeFiles/stackPour.dir/stackPour.c.obj
D:/C-PL/2021-C-PL-Solution/10-struct/stackPour.c
10-struct/cmake-build-debug/CMakeFiles/stackPour.dir/depend.make
View file @
1c972109
# Empty dependencies file for stackPour.
# This may be replaced when dependencies are built.
# CMAKE generated file: DO NOT EDIT!
# Generated by "MinGW Makefiles" Generator, CMake Version 3.20
CMakeFiles/stackPour.dir/stackPour.c.obj
:
\
../stackPour.c
10-struct/cmake-build-debug/CMakeFiles/stackPour.dir/objects.a
0 → 100644
View file @
1c972109
File added
10-struct/cmake-build-debug/CMakeFiles/stackPour.dir/stackPour.c.obj
0 → 100644
View file @
1c972109
File added
10-struct/cmake-build-debug/Testing/Temporary/LastTest.log
View file @
1c972109
Start testing: Dec 14 1
0
:5
2
?D1???
Start testing: Dec 14 1
7
:5
5
?D1???
----------------------------------------------------------
End testing: Dec 14 1
0
:5
2
?D1???
End testing: Dec 14 1
7
:5
5
?D1???
10-struct/cmake-build-debug/stackPour.exe
0 → 100644
View file @
1c972109
File added
10-struct/stackPour.c
View file @
1c972109
...
...
@@ -4,12 +4,60 @@
#include
<stdio.h>
#include
<malloc.h>
struct
stack
{
typedef
struct
stack
{
int
pointer
;
// 存放栈的值
int
*
val
;
};
int
val
[
1000006
];
}
STACK
;
void
pour
(
STACK
*
x
,
STACK
*
y
);
void
output
(
STACK
*
stacks
,
int
len
);
int
main
()
{
int
stackAmount
,
n
;
scanf
(
"%d %d"
,
&
stackAmount
,
&
n
);
// 构建一个stack的数组
STACK
*
stacks
=
malloc
((
stackAmount
+
1
)
*
sizeof
(
STACK
));
for
(
int
i
=
1
;
i
<=
stackAmount
;
i
++
)
{
(
stacks
+
i
)
->
pointer
=
0
;
(
stacks
+
i
)
->
val
[
0
]
=
i
;
}
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
x
,
y
;
scanf
(
"%d %d"
,
&
x
,
&
y
);
pour
(
&
stacks
[
x
],
&
stacks
[
y
]);
}
output
(
stacks
,
stackAmount
);
free
(
stacks
);
return
0
;
}
void
pour
(
STACK
*
x
,
STACK
*
y
)
{
// 将x倒入y里面
// 没有元素的话我们将pointer置为-1
int
len
=
x
->
pointer
;
int
index
=
y
->
pointer
;
for
(
int
i
=
len
;
i
>=
0
;
i
--
)
{
y
->
val
[
++
index
]
=
x
->
val
[
i
];
}
x
->
pointer
=
-
1
;
y
->
pointer
=
index
;
}
void
output
(
STACK
*
stacks
,
int
len
)
{
for
(
int
i
=
1
;
i
<=
len
;
i
++
)
{
if
(
stacks
[
i
].
pointer
==
-
1
)
{
printf
(
"0
\n
"
);
}
else
{
int
top
=
stacks
[
i
].
pointer
;
for
(
int
j
=
0
;
j
<=
top
;
j
++
)
{
printf
(
"%d "
,
stacks
[
i
].
val
[
j
]);
}
stacks
[
i
].
pointer
=
-
1
;
printf
(
"
\n
"
);
}
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment