'I wrote a code like this how can i do it like in the photo
#include <iostream>
using namespace std;
struct Dugum {
int veri;
struct Dugum* sonraki;
};
void olustur(struct Dugum** s) { *s = NULL; }
bool bosMu(struct Dugum* s)
{
if (s == NULL)
return 1;
return 0;
}
void ekle(struct Dugum** s, int x)
{
struct Dugum* p = (struct Dugum*)malloc(sizeof(*p));
if (p == NULL) {
fprintf(stderr, "Bellek ayırma başarısız\n");
return;
}
p->veri = x;
p->sonraki = *s;
*s = p;
}
int cikar(struct Dugum** s)
{
int x;
struct Dugum* gecici;
x = (*s)->veri;
gecici = *s;
(*s) = (*s)->sonraki;
free(gecici);
return x;
}
int tepe(struct Dugum* s) { return (s->veri); }
void siraliEkle(struct Dugum** s, int x)
{
if (bosMu(*s) or x > tepe(*s)) {
ekle(s, x);
return;
}
int gecici = cikar(s);
siraliEkle(s, x);
ekle(s, gecici);
}
void yiginCikar(struct Dugum** s)
{
if (!bosMu(*s)) {
int x = cikar(s);
yiginCikar(s);
siraliEkle(s, x);
}
}
void yazdir(struct Dugum* s)
{
while (s) {
cout << s->veri << " ";
s = s->sonraki;
}
cout << "\n";
}
int main(void)
{
struct Dugum* tepe;
olustur(&tepe);
ekle(&tepe, 3);
ekle(&tepe, 1);
ekle(&tepe, 7);
ekle(&tepe, 4);
ekle(&tepe, 8);
cout << "Orjinal Yigin:\n";
yazdir(tepe);
cout << "\n\n---yiginCikar fonksiyon cagrisi---\n\n";
yiginCikar(&tepe);
cout << "\n";
cout << "Sirali Yigin:\n";
yazdir(tepe);
return 0;
}
[enter image description here][1] How Can I make it like this
what i need is to have it done with a single method inside the main method Add the values 3,1,7,4,8 to the designed stack data structure in order. Stack the values you add print it on the screen, taking into account the initial state. Then, remove the elements in the stack from the stack. Design a recursive method that outputs the signature void heap(Heap *s). In this method, void will be called recursively after all elements have been removed from the stack. Recursively sequentially appending to the stack with the signature Add Sort(Heap *s, int x) Design the method that does the operation. StackRemove method inside the Main function After it is called, print the final version of the stack back to the screen. [1]: https://i.stack.imgur.com/7Sy5m.png
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
