Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
rakein
/
iag0582
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d87b34f8
authored
May 02, 2017
by
rakein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
102b6d5b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
337 additions
and
0 deletions
usfl.c
usfl.c
0 → 100644
View file @
d87b34f8
/**failikontroll**/
int
chkFile
(
FILE
*
file
){
if
(
file
!=
NULL
){
return
0
;
}
return
1
;
/**
if(chkFile(F1) == 1){
printf("faili pole\n");
return 0;
int chkFile(FILE *file);
}**/
/**structi lugemine**/
baas
*
readBaas
(
int
*
Total
,
FILE
*
F1
){
int
i
=
0
;
baas
bufr
;
baas
*
pArr
=
NULL
;
baas
*
pTemp
=
NULL
;
while
(
fscanf
(
F1
,
"%s%lf"
,
bufr
.
toode
,
&
bufr
.
hind
)
!=
EOF
){
pTemp
=
(
baas
*
)
realloc
(
pArr
,
sizeof
(
baas
)
*
(
i
+
1
));
if
(
pTemp
==
NULL
){
printf
(
"M2lu m22ramine eba6nnestus!"
);
free
(
pArr
);
fclose
(
F1
);
exit
(
1
);
}
else
{
pArr
=
pTemp
;
(
pArr
+
i
)
->
hind
=
bufr
.
hind
;
strcpy
((
pArr
+
i
)
->
toode
,
bufr
.
toode
);
i
++
;
}
}
*
Total
=
i
;
return
pArr
;
}
/**
#define <stdlib.h>
#define <string.h>
baas *readBaas(int *Total, FILE *F1);
maini
int tootedTotal;
baas *A = readBaas(&tootedTotal, F1);
free(A);
**/
/**v2ljastus**/
void
v2ljastus
(
int
kogus
,
baas
*
A
){
int
i
;
FILE
*
F2
;
F2
=
fopen
(
"F2(164825).txt"
,
"w"
);
for
(
i
=
0
;
i
<
kogus
;
i
++
){
if
(
S
>=
((
A
+
i
)
->
hind
)){
fprintf
(
F2
,
"%s %0.2lf
\n
"
,
(
A
+
i
)
->
toode
,(
A
+
i
)
->
hind
);
S
-=
((
A
+
i
)
->
hind
);
}
else
{
printf
(
"ostmata j22vad %s %0.2lf
\n
"
,
(
A
+
i
)
->
toode
,(
A
+
i
)
->
hind
);
}
}
printf
(
"alles j2i %0.2lf"
,
S
);
fclose
(
F2
);
}
/**DEK
void v2ljastus(int kogus, double S, baas *A);
v2ljastus(tootedTotal, S, A);**/
///kahe arvu asukoha vahetus
void
swap2
(
int
*
x
,
int
*
y
){
int
temp
;
temp
=
*
x
;
*
x
=
*
y
;
*
y
=
temp
;
}
///.txt lisamine faili nime l6ppu
char
*
kontroll
(
char
*
filename
){
printf
(
"Sisestage sorteeritava faili nimi:
\n
"
);
scanf
(
"%s"
,
filename
);
int
pikkus
;
int
i
;
int
j
=
4
;
int
cmp
;
char
str
[
5
];
char
str1
[
5
]
=
".txt"
;
pikkus
=
strlen
(
filename
);
for
(
i
=
0
;
i
<
5
;
i
++
){
str
[
j
]
=
*
(
filename
+
(
pikkus
-
i
));
j
--
;
}
cmp
=
strcmp
(
str1
,
str
);
if
(
cmp
!=
0
){
strcat
(
filename
,
str1
);
}
return
filename
;
}
/**quicksortt**/
void
quicksorter
(
int
*
nr
,
int
m
,
int
n
,
int
pikkus
){
int
key
,
i
,
j
,
k
;
int
list
[
256
];
for
(
i
=
0
;
i
<
pikkus
;
i
++
){
list
[
i
]
=*
(
nr
+
i
);
}
if
(
m
<
n
){
k
=
choose_midnr
(
m
,
n
);
swap2
(
&
list
[
m
],
&
list
[
k
]);
key
=
list
[
m
];
i
=
m
+
1
;
j
=
n
;
while
(
i
<=
j
){
while
((
i
<=
n
)
&&
(
list
[
i
]
<=
key
))
i
++
;
while
((
j
>=
m
)
&&
(
list
[
j
]
>
key
))
j
--
;
if
(
i
<
j
)
swap2
(
&
list
[
i
],
&
list
[
j
]);
}
swap2
(
&
list
[
m
],
&
list
[
j
]);
quicksorter
(
list
,
m
,
j
-
1
,
pikkus
);
quicksorter
(
list
,
j
+
1
,
n
,
pikkus
);
for
(
i
=
0
;
i
<
pikkus
;
i
++
){
*
(
nr
+
i
)
=
list
[
i
];
}
}
}
/**rekursiiv**/
int
factorial
(
int
x
)
{
if
(
x
==
1
){
return
1
;
}
x
*=
factorial
(
x
-
1
);
return
x
;
}
/**stackexample**/
struct
stack
/* Structure definition for stack */
{
int
stk
[
MAXSIZE
];
int
top
;
};
typedef
struct
stack
STACK
;
STACK
s
;
/* Function declaration/Prototype*/
void
push
(
void
);
int
pop
(
void
);
void
display
(
void
);
void
main
()
{
int
choice
;
int
option
=
1
;
clrscr
();
s
.
top
=
-
1
;
printf
(
"STACK OPERATION
\n
"
);
while
(
option
)
{
printf
(
"------------------------------------------
\n
"
);
printf
(
" 1 --> PUSH
\n
"
);
printf
(
" 2 --> POP
\n
"
);
printf
(
" 3 --> DISPLAY
\n
"
);
printf
(
" 4 --> EXIT
\n
"
);
printf
(
"------------------------------------------
\n
"
);
printf
(
"Enter your choice
\n
"
);
scanf
(
"%d"
,
&
choice
);
switch
(
choice
)
{
case
1
:
push
();
break
;
case
2
:
pop
();
break
;
case
3
:
display
();
break
;
case
4
:
return
;
}
fflush
(
stdin
);
printf
(
"Do you want to continue(Type 0 or 1)?
\n
"
);
scanf
(
"%d"
,
&
option
);
}
}
/*Function to add an element to the stack*/
void
push
()
{
int
num
;
if
(
s
.
top
==
(
MAXSIZE
-
1
))
{
printf
(
"Stack is Full
\n
"
);
return
;
}
else
{
printf
(
"Enter the element to be pushed
\n
"
);
scanf
(
"%d"
,
&
num
);
s
.
top
=
s
.
top
+
1
;
s
.
stk
[
s
.
top
]
=
num
;
}
return
;
}
/*Function to delete an element from the stack*/
int
pop
()
{
int
num
;
if
(
s
.
top
==
-
1
)
{
printf
(
"Stack is Empty
\n
"
);
return
(
s
.
top
);
}
else
{
num
=
s
.
stk
[
s
.
top
];
printf
(
"poped element is = %d
\n
"
,
s
.
stk
[
s
.
top
]);
s
.
top
=
s
.
top
-
1
;
}
return
(
num
);
}
/*Function to display the status of the stack*/
void
display
()
{
int
i
;
if
(
s
.
top
==
-
1
)
{
printf
(
"Stack is empty
\n
"
);
return
;
}
else
{
printf
(
"
\n
The status of the stack is
\n
"
);
for
(
i
=
s
.
top
;
i
>=
0
;
i
--
)
{
printf
(
"%d
\n
"
,
s
.
stk
[
i
]);
}
}
printf
(
"
\n
"
);
}
/*---------------------------------------------------------------------------
Output
STACK OPERATION
------------------------------------------
1 --> PUSH
2 --> POP
3 --> DISPLAY
4 --> EXIT
------------------------------------------
Enter your choice
1
Enter the element to be pushed
23
Do you want to continue(Type 0 or 1)?
1
------------------------------------------
1 --> PUSH
2 --> POP
3 --> DISPLAY
4 --> EXIT
------------------------------------------
Enter your choice
1
Enter the element to be pushed
45
Do you want to continue(Type 0 or 1)?
1
------------------------------------------
1 --> PUSH
2 --> POP
3 --> DISPLAY
4 --> EXIT
------------------------------------------
Enter your choice
1
Enter the element to be pushed
78
Do you want to continue(Type 0 or 1)?
1
------------------------------------------
1 --> PUSH
2 --> POP
3 --> DISPLAY
4 --> EXIT
------------------------------------------
Enter your choice
3
The status of the stack is
78
45
23
Do you want to continue(Type 0 or 1)?
1
------------------------------------------
1 --> PUSH
2 --> POP
3 --> DISPLAY
4 --> EXIT
------------------------------------------
Enter your choice
2
poped element is = 78
Do you want to continue(Type 0 or 1)?
1
------------------------------------------
1 --> PUSH
2 --> POP
3 --> DISPLAY
4 --> EXIT
------------------------------------------
Enter your choice
3
The status of the stack is
45
23
Do you want to continue(Type 0 or 1)?
0
-----------------------------------------------------------------------------*/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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