The following basic operations are programmed to implement the order table: set up the order table, modify the order table, insert the Order table, and delete the order table.

Source: Internet
Author: User

#include <iostream> #include <stdio.h> #include <stdlib.h>using namespace std;typedef int elemtype; typedef int STATUS; #define OK 1#define ERROR 0#define overflow-2#define list_init_size 100#define listincrement 10ElemTyp    E * newbase,*p,*q;//Sequence table structure description typedef struct{ELEMTYPE *elem;    int length; int listsize;} Initialization of the sqlist;//Order table status initlist_sq (SqList &l) {//Constructs an empty linear table L L.elem = (Elemtype *) malloc (list_init_size*sizeof (El    Emtype)); if (! L.elem) exit (OVERFLOW);   Storage allocation Failure l.length = 0;    Empty table length is 0 l.listsize = list_init_size; Initial storage capacity return OK;}    initlist_sq//the establishment of the Order table void creat_sq (SqList &l) {int i,n;    cout<< "Please enter the number of elements in the sequential table:";    cin>>n;        for (i=0;i<n;i++) {cout<< "Please enter" << (i+1) << "elements:";        cin>>l.elem[i];    l.length++;    }}//display of the sequential table void show_sq (SqList L) {for (int i=0;i<l.length;i++) {cout<<l.elem[i]<< ""; } Cout<<endl;} Insert status LISTINSERT_SQ for sequential tables (SqLiSt &l,int I,elemtype e) {if (i<1| |        i>l.length+1) {cout<< "I value is not valid" <<endl;    return ERROR; } if (l.length>=l.listsize) {newbase = (Elemtype *) realloc (L.elem, (l.listsize+listincrement) *sizeof (ElemType))        ;        if (!newbase) exit (OVERFLOW);        L.elem = Newbase;    L.listsize + = listincrement;    } q = & (L.elem[i-1]);    for (P = & (L.elem[l.length-1]);p >=q;--p) {* (p+1) = *p;    } *q = e;    ++l.length; return OK;} Deletion of the sequential table status listdel_sq (sqlist &l,int i,elemtype e) {if (i<1| |        i>l.length+1) {cout<< "I value is not valid" <<endl;    return ERROR;    } q = & (L.elem[l.length-1]);    For (p=& (l.elem[i-1]);p <=q;p++) {*p=* (p+1);    } e=*q;    --l.length; return OK;} Modify the Order table status listupdate_sq (sqlist &l,int i,elemtype e) {if (i<1| |        i>l.length+1) {cout<< "I value is not valid" <<endl;    return ERROR;    } l.elem[i-1] = e; return OK;} int main () {SqLiSt L;    INITLIST_SQ (L);    CREAT_SQ (L);    SHOW_SQ (L);    int num=0,i;    Elemtype e;    BOOL flag = TRUE;        while (flag) {cout<< "1. Insert" << "2. Delete" << "3. Modify" <<endl;        cout<< "Please enter the sequence number to perform the operation:";        cin>>num;        if (num>=1&&num<=3) {flag=false;        }else{cout<< "Input illegal" <<endl;            }} switch (num) {Case 1: {cout<< "Please enter the location to insert:";            cin>>i;            cout<< "Please enter the number to insert:";            cin>>e;        LISTINSERT_SQ (l,i,e);        }break;            Case 2: {cout<< "Please enter the location to delete:";            cin>>i;        LISTDEL_SQ (l,i,e);        }break;            Case 3: {cout<< "Please enter the location to be modified:";            cin>>i;            cout<< "Please enter the modified number:";            cin>>e;        LISTUPDATE_SQ (l,i,e);    }break;    } show_sq (L); return 0;}


The following basic operations are programmed to implement the order table: set up the order table, modify the order table, insert the Order table, and delete the order table.

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.