⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pex9_6.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#include <iostream.h>
#include <stdlib.h>
#pragma hdrstop

#include "node.h"
#include "nodelib.h"

void main(void)
{
	// build linked list with head list. use currPtr
	// to traverse the list
	Node<int> *list = NULL, *currPtr;
	int item;

	// build a 5 element list
	for (int i = 0; i < 5; i++)
	{
		// read an integer and insert it at front of list
		cin >> item;
		InsertFront(list,item);
		
		// scan all nodes to the right of the new node
		// and delete all those whose data value is < item
		currPtr = list;
		while (currPtr->NextNode() != NULL)
			// is the data value in the node following currPtr < item?
			if ((currPtr->NextNode())->data < item)
				// delete node following currPtr. currPtr does
				// not move forward
				currPtr->DeleteAfter();
			else
				// move currPtr forward
				currPtr = currPtr->NextNode();
	}
	
	// print the list
	PrintList(list); 
	cout << endl;
}
/*
<Run #1>
1 2 3 4 5 
5

<Run #2>
5 4 3 2 1 
1  2  3  4  5

<Run #3>
3 5 1 2 4
4  5
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -