Advertisement
2_2002-2004 Data Structures #127237

Link list (queue)

produces a link list as a queue. it is part of my billing project and so uses order placing. nothing complicated.

AI

AI-sammanfattning: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Källkod
original-source
//	Author:		Mohammed Ali Akbani
//	E-mail:		[email protected]
//	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 );
}
Upload
Upload
Originalkommentarer (3)
Återställd från Wayback Machine