~cpp 
#include <iostream>
#include <cstring>
using namespace std; 

struct data{
	char addressNumber[8]; 
	char name[20]; 
	char address[100];
	data * next;
}; 

void showMenu(); 
data * enterName(data * firstData);	 // case 1 
data * deleteName(data * firstData);	 // case 2 
void showList(data * firstData);	 // case 3 

unsigned int count=0;


int main() 
{
	data * firstData = new data;
	firstData = NULL;
	char menuNumber; 
	while(1)
	{
		showMenu();
		cin >> menuNumber; 
		switch ( menuNumber ) 
		{ 
		case '1': 
			count++;
			firstData = enterName(firstData);
			break; 
		case '2': 
			if ( count > 0 ) 
			{ 
				count--; 
				firstData = deleteName(firstData); 
			} 
			else 
			{ 
				cout << "Don't use this menu, yet."; 
				showMenu(); 
			} 
			break; 
		case '3': 
			showList(firstData); 
			break; 
		case '4': 
			return 0; 
			break;
		default: 
			system("cls"); 
			showMenu(); 
			break; 
		}
	}

	return 0; 
} 

void showMenu() 
{ 
	cout << "\tM E N U\n" 
		 << "1> Input data\n" 
		 << "2> Delete data\n" 
		 << "3> Show list\n" 
		 << "4> Quit\n" 
		 << "Selete number> "; 
} 

data * enterName(data * firstData) 
{
	system("cls");
	data * temp = new data;
	char addNum[8],	nam[20], add[100];
	cout << "Enter name :";
	cin >> nam;
	cout << "Enter address :";
	cin.get();
	cin.getline(add,99);
	cout << "Enter address number :";
	cin >> addNum;
	cin.get();
	if(firstData == NULL)  
	{
		firstData = new data;
		strcpy(firstData->name, nam);
		strcpy(firstData->address, add);
		strcpy(firstData->addressNumber, addNum);
		firstData->next = NULL;
	}  
    else  
    {  
		temp->next = firstData;
		firstData = temp;  
		strcpy(firstData->name, nam);
		strcpy(firstData->address, add);
		strcpy(firstData->addressNumber, addNum);
	}
	return firstData;	
} 

data * deleteName(data * firstData) 
{ 
	system("cls");
	char nam[20];
	cout << "Enter name what you want : ";
	cin >> nam;
	
	data * temp = new data;
	data * temp_co;
	temp_co = NULL;
	while(firstData != NULL)
	{
		if ( !(strcmp(firstData->name, nam) == 0) )
		{
			if (temp_co == NULL)
			{
				temp_co = new data;
				strcpy(temp_co->name, firstData->name);
				strcpy(temp_co->address, firstData->address);
				strcpy(temp_co->addressNumber, firstData->addressNumber);
				temp_co->next = NULL;
			}
			else
			{
				temp = new data;
				temp->next = temp_co;
				temp_co = temp;
				strcpy(temp_co->name, firstData->name);
				strcpy(temp_co->address, firstData->address);
				strcpy(temp_co->addressNumber, firstData->addressNumber);
			}
		}
		firstData = firstData->next;
	}
	firstData = temp_co;
	return firstData;
} 

void showList(data * firstData) 
{
	system("cls");
	data * temp;
	temp = firstData;
	cout << "\t\t# L i s t #\n\n";
	while(temp != NULL)
	{
		cout << "○" << temp->name << "\t" << temp->address << "\t" << temp->addressNumber << endl;
		temp = temp->next;
	}
	cin.get();
	cin.get();
} 



Retrieved from http://wiki.zeropage.org/wiki.php/whiteblue/LinkedListAddressMemo
last modified 2021-02-07 05:31:46