1. Postgraduate Examination-data structure-sequential table problems

Source: Internet
Author: User
Requires building a sequential table that implements
Operation: 1, find the maximum value in the list 2, set the positive sequence output
     3, insert an element 4, delete element 5 in the collection, reverse the Set output   6, exit the system
#include "stdafx.h" #include <iostream> #define OK 1 #define MAXSIZE #define ERROR 0 using namespace std;
	typedef struct {int data[maxsize];
int length;
}sqlist;
	/* Create order Table */void CreateList (SqList *list) {cout << "Please enter element" << Endl;
	for (int i = 0; i < list->length; i++) {cin >> list->data[i];
	}}/* Show order table */void Showlist (SqList *list) {cout << "Your order table is:" << Endl;
	for (int i = 0; i < list->length; i++) {cout << list->data[i]<< "";
	}/* * Find maximum value */int Findmax (sqlist list) {int max=list.data[0];
		for (int i = 1; i < list.length; i++) {if (Max<list.data[i]) {max = list.data[i];
}} return max; }/* Sort order table */void Sortlist (SqList *list) {for (int i = 0; i < list->length; i++) {for (int j = 0; J < list->length;
			J + +) {int temp;
				if (List->data[i]<list->data[j]) {temp = list->data[i];
				List->data[i] = list->data[j]; List->dATA[J] = temp;

}}} showlist (list); }/* Insert an element */void Insertlist (sqlist *list,int num,int position) {if (position>list->length| |
		position<1) {cout << "wrong postion";
	Return
	} list->length++;
	for (int i = list->length; I >=position+1; i--) {list->data[i-1] = list->data[i-2];
	} list->data[position-1] = num;
Showlist (list); }/* Deletes an element */void DeleteList (sqlist *list, int position) {if (position>list->length| |
	position<1) {return;
	} for (int i = position-1; i < list->length-1; i++) {List->data[i] = list->data[i + 1];
	} list->length--;
Showlist (list);
		}/* Reverse output a sequential table */void disorder (SqList *list) {int num = list->length;
			for (int i = 0; i < list->length/2; i++) {int temp;
			temp = list->data[i];
			List->data[i] = list->data[list->length-i-1];
	List->data[list->length-i-1] = temp;

} showlist (list); } int main () {SqList list;//defines aSequential table name is List//create a sequential table cout << "Please enter the number of elements you want to enter:" << Endl;
	Cin >> List.length;
	CreateList (&list);
	Showlist (&list);
	int order = 0;
	BOOL flag = TRUE;
		while (flag) {cout << endl << endl << "action: 1, find the maximum value in the list 2, set the positive sequence output" << Endl;
		cout << "3, insert an element 4, delete element 5 in the collection, reverse the Set output 6, exit the system" << Endl;
		CIN >> Order;
			Switch (order) {case 1:cout << "Maximum is" << Findmax (list);
		Break
			Case 2:sortlist (&list);
		Break
			Case 3:int num, position;
			cout << "The element to be inserted is";
			CIN >> Num;
			cout << "where you want to insert is";
		    CIN >> Position;
			Insertlist (&list, num, position);
		Break
			Case 4:int Position_del;
			cout << Endl << "where you want to remove the element:";
			Cin >> Position_del;
			DeleteList (&list, Position_del);
		Break
			Case 5:disorder (&list);
		Break
			Case 6:flag = false;
		Break
}} return 0;
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.