Delete a node from a single-chain table with no Headers

Source: Internet
Author: User
// Programming beauty question. This question has two restrictions. The deleted node cannot be the first or last one. // 1. the last node cannot be deleted because it points to a deleted pointer. // 2. why cannot I delete the first node? // Use the CAPTCHA technology to delete the next node and copy the data of the next node to the previous node # include <stdio. h> # include <stdlib. h> # include <assert. h> typedef struct node {int data; node * Next;}; void deletemidnode (node * P) {assert (P! = NULL); node * pnext = p-> next; If (pnext! = NULL) {P-> next = pnext-> next; P-> DATA = pnext-> data; Delete pnext ;}} void print (node * HD) {// P ++ is written here. The error for (node * P = HD-> next; P = p-> next) printf ("% d ", p-> data); printf ("\ n");} int main () {int A [5] = {1, 2, 3, 4, 5 }; node * head = new node; head-> next = NULL; For (INT I = 0; I <5; I ++) {node * TMP = new node; TMP-> DATA = A [I]; TMP-> next = head-> next; head-> next = TMP;} print (head ); deletemidnode (Head-> next); print (head); System ("pause"); 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.