Scut data structure Big job first problem single linked list Delete Create a variety of easy operations

Source: Internet
Author: User

#include <iostream> #include <windows.h> #include <string>/* (1) Initialize single-linked list H; (2) Insert 5 elements in turn: {"Zhang San", 85}, {"John Doe", 95}, {"Harry", 75}, {"Chen June", 80}, {"Tao Cheng", 90} (3) Outputs the contents of the single-linked list H; (4) The length of the output single-linked list; (5) Output order The 3rd element of the list H; (6) Enter a name (for example: Chen June), find the element in a single-linked list, output the number of the element, (7) Delete the 4th element, and output the contents of the deleted element; (8) The contents of the output single-linked list H; (9) Release      Put a single linked list H. Note: Each procedure displays a variety of informational messages.    For example: the length of the output single-linked list is required to display: The current single-linked list length is: 5.*/using namespace std; struct student{string name; int score;}    ; typedef Student ELEMTYPE; struct linklist{elemtype data; linklist * LINK; Linklist (linklist *ptr = NULL) {link = ptr;}}    ;//heavy-duty write here IStream &operator>> (IStream &is,elemtype &c) {is >> c.name>>c.score; return is;}    Ostream &operator<< (ostream &os,elemtype &c) {os << c.name<< c.score; return OS;} void print (Linklist *first) {linklist *cur = first; cur = cur-link; while (cur! = NULL) {cout <<cur->data &Lt;<endl; cur = cur->link;  }}//Code Error//The problem is that the first link is empty, and there is no connection down void Printlen (linklist *first) {int length = 0; if (first->link = = NULL) {cout << "Fuckashole" &LT;&LT;ENDL;}  while (first! = NULL) {//cout<<cur->dat<<endl;length++; first =first->link;} cout << "The length of the list is:" << length-1 <<endl;} Linklist *locate (linklist *first, int w_place) {//locator function, insert and delete when used to determine a position int k = 0; linklist *cur = first; while (k! = w_place) {cur = cur->link; k++;} return cur;} void Locpri (linklist *&first) {cout << "Please enter the location you want to output:"; int lp_number; Cin >> Lp_number; Locate (First, Lp_number), cout <<locate (First, lp_number)->data <<endl;} void Create (linklist *&first, int n) {//n is the cout<< of the first node "Please enter object:" <<endl; Elemtype n_data; Cin >> N_data;  First->link = NULL;//first->data = n_data;//This side needs to be overloaded linklist *cur = new linklist; Cur->link =first->link ; first->link = cur; cur->data =N_data; linklist *f = new linklist; f = cur;for (int i=0; i< n-1; i++) {cout<< "Please enter object:" <<endl; Elemtype n_data; Cin >> N_data; First->link = NULL;//first->data = n_data;//This side needs to be overloaded linklist *cur = new linklist; Cur->link =f->link; f >link = cur; cur->data = n_data; f = cur;//the wrong part//first = cur;}} /*void Insert (linklist *first) {//cout<< "Please enter the location you want to insert:";//int place;//cin >> places; Linklist *cur =locate (first,place); linklist *newnode = new linklist;cout<< "Please enter the value of the element you want to insert:"; Elemtype data; NewNode->link =null; Cin >> Data.name>>data.score;//or need to use overloaded newnode->data = data; Newnode->link = cur->link; cur->link = NewNode;} */void Delete (linklist *first) {cout<< "Please enter the location you want to delete:"; int place; Cin >> places; Linklist *cur =locate (first,place-1); Cur->link =cur->link->link;} void Search (linklist *first, elemtype test) {//cout << "Please enter the element name you want to find:";//elemtype test;//cin >> test; int flag = 0; int k = 0;//if (first->link = = null) cout << "link of Search is empty" <<endl;while (Fir St! = NULL) {if (First->data.name = = test.name) {//cout << "find this element" &LT;&LT;ENDL; flag = 1; k++; break; }else {first = First->link; k++;//search (first, test);}} if (flag = = 0) {cout << "the element was not found" &LT;&LT;ENDL;} if (flag = = 1) {//cout << "found the element" &LT;&LT;ENDL; cout << "The location of the element found is:" << K-1<<endl;}} int main () {//cout<< "Please enter the number of elements you want to insert:";/*int W_number; Cin >>w_number; for (int i =0; i < w_number; i++) {//Insert each element}*/cout << "Please enter the number of objects you want to create:"; int w_number; Cin >>w_number; linklist *test = new linklist; Test-link = NULL; The new header is empty//cout<< "Please enter object:" <<endl;//elemtype t_data;//cin>>t_data;//test->data = T_data; create (test,w_number); cout <<endl;cout <<endl;print (test); cout << Endl;printlen (test);//Find part cout &LT;&L T;endl; LOCPRI (test);cout << "Please enter the name of the element you want to find:"; Elemtype tes, CIN >> tes.name; cout <<endl; Search (test, TES), cout <<endl;delete (test);p rint (test), cout <<endl;p rint (test); System ("pause"); Retu RN 0;}

Scut data structure Big job first problem single linked list Delete Create a variety of easy operations

Related Article

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.