Академический Документы
Профессиональный Документы
Культура Документы
#include<iostream.h>
#include<process.h>
#include<conio.h>
struct Node{int info; //for exit()
Node*next;
}*front,*newptr,*save,*ptr,*rear;
Node*Create_New_Node(int);
void Insert(Node*);
void Display(Node*);
void DelNode_Q();
void main()
{front=rear=NULL; //In the beginning Linked-Queue isn empty,thus,pointers are NULL
int inf;char ch ='y';
while(ch=='y'||ch=='Y')
{ cout<<"\n Enter INFOrmation for the new code....";
cin>>inf;
newptr= Create_New_Node(inf);
if(newptr==NULL)
{cout<<"\nCannot crete new Node!!!Aborting!!\n";exit(1);}
Insert(newptr);
cout<<"\nPress Y to enter more nodes,N to exit...\n";
cin>>ch;
}
clrscr();
do
{cout<<"\n The Linked-Queue now is(Front...to..Rear):\n";
Display(front);
cout<<"Want to delete first node?(y/n)...";
cin>>ch;
if(ch=='y'||ch=='Y')
DElNode_Q();
}while(ch=='y'||ch=='Y');
}
Node*Create_New_Node(int n) //Function to create new node dynamically
{ ptr=new Node;
ptr->info=n; ptr->next=NULL;
return ptr;
}
void Insert(Node*np) //Function to insert node in the Linked_Queue
{ if(front==NULL){front=rear=np;}
else
{rear->next=np; rear=np;}
//FILE HANDLING
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
char rec[80],ch;
char fname[20];
int count =0,i;
char ans =’y’;
clrscr();
cout<<”Enter file name:”;
cin.get(fname,20);
ofstream fout(fname,ios::out);
if(!fout)
{cout<<”Error in creating file..!!\n”;
cout<<”Press any key to exit..!!\n”;
getch();
exit(1);
}
cin.get(ch);
cout<<”Enter information to store..\n”;
while(ans==’y’||ans==’Y’)
{
cin.get(rec,80);
fout<<rec<<”\n”;
cout<<”Want to enter more?(y/n)..”;
cin>>ans;
count++;
cin.get(ch);
}
cout<<”\nThe information successfully stored in the file..!!\n”;
fout.close();
cin.get(ch);
cout<<”Want to see? (y/n)..”;
cin>>ans;
if(ans==’y’||ans==’Y’)
{
ifstream fin(fname,ios::in);
if(!fin)
{
cout<<”Error in opening the file..!!\n”;
cout<<”Press any key to exit..\n”;
getch();
exit(2);
}
fin.seekg(0);
cout<<”\n”;
Want to see..(y/n).. y