// main.cpp // linklist #include struct Node { int d; Node *link; }; Node *first=0; void Add(int); Node* Find(int); void Delete(int); void Display(void); void Clear(void); int Menue(void); int main (int argc, const char * argv[]) { int i; while(1) { switch (Menue()){ case 1: scanf("%d",&i); Add(i); break; case 2: scanf("%d",&i); Find(i); break; case 3: scanf("%d",&i); Delete(i); break; case 4: Display(); break; case 5: Clear(); break; case 6: return 0; } } } //******************** int Menue(void) { int i; printf("1.Add Number\n"); printf("2.Find Number\n"); printf("3.Delete Number\n"); printf("4.Display Number\n"); printf("5.Clear List\n"); printf("6.exit\n"); printf("Enter your choose:"); scanf("%d",&i); return i; } //******************** void Add(int d) { Node *temp; temp=new Node; temp->d=d; temp->link=first; first=temp; } //******************** Node* Find(int d) { Node *temp=first; while(temp) { if(d==temp->d) return temp; temp=temp->link; } return 0; } //******************** void Delete(int d) { if(!first) return; Node *temp=first; if(first->d==d) { first=first->link; delete temp; return; } Node *cur=first->link; while(temp->link) { if(cur->d==d) { temp->link=cur->link; delete cur; return; } temp=cur; cur=cur->link; } } //******************** void Display(void) { Node *temp=first; while (temp) { printf("%d-",temp->d); temp=temp->link; } printf("\n"); } //******************** void Clear(void) { Node *temp,*cur=first; while (cur!=0) { temp=cur; cur=cur->link; delete temp; } }