原创 shell腳本學習(二):文件比較等操作

對應《Linux命令行與shell腳本編程大全》 -- 章節12.4.3 test1: -d file :檢查目錄 #!/bin/bash dir="/home//shell/dir" if [ -d $dir ] then

原创 shell腳本學習(三)

test1:for循環 #!/bin/bash for var in one two three four do echo "The number is $var" done echo "Now show read v

原创 shell腳本實踐1:截取字符串

請根據以下要求截取出字符串中的字符:http://www.aaa.com/root/123.htm 1.取出www.aaa.com/root/123.htm 2.取出123.htm 3.取出http://www.aaa.com/root

原创 shell腳本實踐2:自定義rm命令

linux系統的rm命令太危險,一不小心就會刪除掉系統文件。 寫一個shell腳本來替換系統的rm命令,要求當刪除一個文件或者目錄時,都要做一個備份,然後再刪除。 1. 簡單的實現: 假設有一個大的分區/data/,每次刪除文件或者目錄之

原创 Linux下vim編輯退出的命令(據說70%的程序員都不會)

很久以前,江湖中流傳着一個神祕的問題:如何退出Vim編輯器? 據說,很多人老死都沒有退出Vim,也沒有人知道答案。(太扎程序員的心了!!!)   ESC進入“正常模式”,然後輸入“:”,進入“命令模式”。此時屏幕的下方會出現一個冒號,你可

原创 1. C++多態

多態就是多種形態,C++的多態分爲靜態多態與動態多態。 函數重載就是一個簡單的靜態多態,靜態多態是編譯器在編譯期間完成的,編譯器會根據實參類型來選擇調用合適的函數,如果有合適的函數可以調用就調,沒有的話就會發出警告或者報錯。   動態多

原创 LeetCode:206. Reverse Linked List

一、問題描述 Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL 二、代碼實現 /** * De

原创 LeetCode:237. Delete Node in a Linked List

一、問題描述 Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Giv

原创 STL:list用法總結

原文鏈接:https://blog.csdn.net/xiaoquantouer/article/details/70339869 list用法彙總 https://blog.csdn.net/

原创 LeetCode:19. Remove Nth Node From End of List

一、問題描述 Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list:

原创 單鏈表:從頭到尾打印鏈表

解題思路: 第一種方法:逆置單鏈表,然後輸出; 第二種方法:利用棧的特性(先進後出),從頭部入棧,然後出棧即可; 下面着重實現第二種方法。 代碼實現 /** * struct ListNode { * int val;

原创 LeetCode:92. Reverse Linked List II

一、問題介紹 Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: Input

原创 LeetCode:234. 迴文鏈表

一、問題描述 請判斷一個鏈表是否爲迴文鏈表。 示例 1: 輸入: 1->2 輸出: false 示例 2: 輸入: 1->2->2->1 輸出: true 二、解題思路 將鏈表分爲兩段,並且把後面一段進行倒置,然後再比較前後兩段是否相

原创 LeetCode:138. 複製帶隨機指針的鏈表

一、問題描述 給定一個鏈表,每個節點包含一個額外增加的隨機指針,該指針可以指向鏈表中的任何節點或空節點。 二、解題思路 第一種:用hashmap,遍歷鏈表然後把它存到 HashMap 中,val 作爲 key,Node 作爲 value。

原创 LeetCode:23. Merge k Sorted Lists

一、問題描述 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: Inp