VB icon

Link list (queue)

Email
Submitted on: 1/1/2015 4:38:00 PM
By: Mohammed Ali Akbani (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: C, C++ (general), Borland C++
Views: 1022
 
     produces a link list as a queue. it is part of my billing project and so uses order placing. nothing complicated.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Link list (queue)
// Description:produces a link list as a queue. it is part of my billing project and so uses order placing. nothing complicated.
// By: Mohammed Ali Akbani (from psc cd)
//**************************************

//	Author:		Mohammed Ali Akbani
//	E-mail:		duke@samwonline.com
//	Level :		beginner
//		Please do not repost it in you name, and vote for me.
#include <iostream.h>
#include <conio.h>
struct order
{
	char	code[7];
	int qnty;
	order	*next;
};
order *first, *view, *previous, *neworder; //pointers to keep track of the nodes in the list
void new_order( int &order_no ) //adds a new node in the list
{
		if( order_no > 0 )
		{
			neworder = new order;//if a order already exists in the list
			previous -> next = neworder;//previous node now points to the new node 
			neworder -> next = NULL;//the new order now points to NULL meaning
			previous = neworder;//its the last node
			order_no++;
		}
			else
			{
				neworder = new order;
				neworder -> next = NULL;
				previous = first = neworder;
				order_no++;
			}
}
void delete_bill( int &order_no) // all the nodes are deleted
{
		previous = first;
		for( int j=0; j<order_no; j++ )
		{
			previous = previous -> next;
			delete first;
			first = previous;
		}
}
void main()
{
	int order_no = 0;
	char choice = 'n';
	first = view = previous = neworder = NULL;
	while( choice == 'n' )
	{
		clrscr(); // comment this line if error generated
			new_order( order_no );
			gotoxy(30,9);
			cout << "Enter item code: ";
			cin >> neworder -> code;
			gotoxy(30,11);
			cout << "Enter number of items: ";
			cin >> neworder -> qnty;
			gotoxy(30,13);
			cout << "Enter choice : ";
			choice = getch();
		}
		view = first;
		clrscr(); // comment this line if error generated
		for( int i=0; i<order_no; i++ ) //shows all the orders placed
		{
			gotoxy(30,i+2);
			cout << view -> code;
			gotoxy(40,i+2);
			cout << view -> qnty;
			view = view -> next;
		}
		getch();
		delete_bill( order_no );
}


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.