亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

求大佬,幫幫忙這是干嘛的,如何運行

#include <iostream>
using namespace std;

class node {
??? public:
??? int data;
??? node *next;
??? node(int x){
??????? data=x;
??????? next=NULL;
??? }
};
class LinkedList{
public:
??? node *head;
??? void addAtFront(node *n){
??????? n->next=head;
??????? head=n;
??? };
??? bool isEmpty(){
??????????? return (head==NULL)?1:0;
??? };
??? void addAtEnd(node *n){
??????? if(head==NULL){
??????????? head=n;
??????????? n->next=NULL;
??????? }
??????? else{
??????????? node *n2=getLastNode();
??????????? n2->next=n;

??????? }
??? };
??? node* getLastNode(){
??????? node* ptr=head;
??????? while(ptr->next!=NULL)
??????????? ptr=ptr->next;
??????? return ptr;
??? };
??? node* search(int k){
??????? node *ptr=head;
??????? while(ptr!=NULL&&ptr->data!=k){
??????????? ptr=ptr->next;
??????? }
??????? return ptr;
??? };
??? node* deleteNode(int x){
??????? node *n=search(x);
??????? node *ptr=head;
??????? if(ptr==n){
??????????? head=n->next;
??????????? return n;
??????? }
??????? else{
??????????? while(ptr->next!=n){
??????????????? ptr=ptr->next;
??????????? }
??????????? ptr->next=n->next;
??????????? return n;
??????? }
??? };
??? void printList(){
??????? node *ptr=head;
??????? while(ptr!=NULL){
??????????? cout<<ptr->data<<"->";
??????????? ptr=ptr->next;
??????? }
??????? cout<<"\n";
??? };
??? LinkedList(){head=NULL;}
};

int main(){
??? LinkedList li;
??? node *n1=new node(1);
??? node *n2=new node(2);
??? node *n3=new node(3);
??? node *n4=new node(4);
??? li.addAtFront(n1);
??? li.printList();
??? li.addAtFront(n2);
??? li.printList();
??? li.addAtEnd(n4);
??? li.addAtEnd(n3);
??? li.printList();
??? li.deleteNode(2);
??? li.printList();
??? return 0;
}


正在回答

2 回答

數據結構里面的鏈表?

0 回復 有任何疑惑可以回復我~

1111

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
C語言入門
  • 參與學習       926913    人
  • 解答問題       21533    個

C語言入門視頻教程,帶你進入編程世界的必修課-C語言

進入課程

求大佬,幫幫忙這是干嘛的,如何運行

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號