Hi!I have a slight problem with this program and I will be glad if anyone can help me:
The elements of the stacks have to be sorted with the bubble sort.
Creates a dynamic structure deque,which contains the elements of the two stacks and finds the smallest number,higher than the average value of all elements in the deque.
Function that reades the elements of the 2 stacks and the deck.The problem is that the sort function and the built function,which I use to create the new deque and to find the smallest number,higher than the average value of the elements of the deque don`t work.
.Thanks in advance!
#include<iostream>
#include<fstream>
using namespace std;
fstream fp;
//Files to read
char t1[]="F1.txt";
char t2[]="F2.txt";
//Files for record
char tt1[]="FF.txt";
//Deque structure
struct dek {
int key;
dek *next;
} *left = NULL, *right=NULL;
//Initialising of the 2 stacks
struct elem{
int key;
elem *next;
} *start1=NULL,*start2=NULL,*p;
void add_1(int n) //Adding elements in the first stack
{
elem *p = start1;
start1 = new elem;
start1->key = n;
start1->next = p;
}
void add_2(int n) //Adding elements in the second stack
{
elem *p = start2;
start2 = new elem;
start2->key = n;
start2->next = p;
}
// Прехвърляне на 1 стек в 1 файл
elem* readFile1(elem *start1, char *t1)
{
elem e; //Local variable of a stack type
int br1; //Local variable,whichs finds the number of elements in the stack
fp.open("F1.txt",ios::binary,ios::app| ios::in|ios::out); //Opens the binary file for reading,recording and applying
if (!fp.fail())
{
cout << "Greshka pri otvarqne! ";
exit(0);
}
fp.write((char*)&e,sizeof(start1)); //1 stacks goes in the file
fp.seekg(0L,ios::beg);
fp.read((char*)&e,br1*sizeof(start1)); //Filling the structure
return start1;