Форум С++

 

Ответить на сообщение

Вернуться к теме

Вы отвечаете на сообщение:

Автор: Мириам   (27.05.2010 в 08:52)
вот примерно так на очередь но она с ошибкой

#include<fstream>
#include<string>

using namespace std;

struct queue{
string inf;
queue *next;};
queue *initqueue(){
return NULL;};

void push(queue *&h,queue *&t, string i){
queue*r=new queue;
r->inf=i;
r->next=NULL;
if(h==NULL) h=r;
else t->next=r;
t=r;}

string pop(queue *&h, queue *&t){
queue*r=h;
string i=r->inf;
h=r->next;
if(h==NULL) t=NULL;
delete r;
return i;}

int main(){
queue *h,*h1,*t,*d,*g,*r;
int s=0;
string i,l,c;
h=initqueue();
h1=initqueue();
t=initqueue();d=initqueue();
g=initqueue();r=initqueue();
ifstream in("in.txt");
ofstream out("out.txt");
while(!in.eof())
{
in>>c;
push(h,t,c);
}
l=pop(h,t);
push(h1,t,l);

while (h!=NULL)
{
i=pop(h,t);
if(l!=i) push(r,g,i);
else push(h1,d,i);
s++;
}
while(h1!=NULL)
{
out<<pop(h1,d)<<' ';
}
out<<s;
return 0;
}


Ваше имя:

Пароль:

Цитировать

Используйте тэги для выделения текста:
Код: [code][/code]
Жирный: [b][/b]
Наклонный: [i][/i]
URL: [url][/url]

Сообщение:

Прикрепить: