// main.cpp // linklist #define _CRT_SECURE_NO_DEPRECATE #include #include "stdafx.h" #include struct Node { int d; Node *link; }; Node *first = 0; void Add(); Node* Find(int); void Delete(int); void Display(void); void Clear(void); int Menue(void); int main() { int i; while (1) { switch (Menue()) { case 1: Add(); 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 n; printf("Enter count:"); scanf("%d", &n); for (int k = 0; k < n; k++) { Node *temp; temp = (Node *)malloc(sizeof Node); int d=0; printf("Enter count:"); scanf("%d", &d); 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; return; } Node *cur = first->link; while (temp->link) { if (cur->d == d) { temp->link = cur->link; 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; first = 0; }